Commit 98590dcc authored by Yeol's avatar Yeol Committed by Commit Bot

Return std::unique_ptr in WrapViewForPreferredSize().

In order to better convey property object ownership,
changed WrapViewForPreferredSize() to take and return std::unique_ptr.

Bug: 961657
Change-Id: Ib06871c5bd0dcef357d160b8784f8541b839f59d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1607707Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Yeol Park <peary2@gmail.com>
Cr-Commit-Position: refs/heads/master@{#663061}
parent aab303d4
...@@ -1121,13 +1121,16 @@ views::LabelButton* LockDebugView::AddButton(const std::string& text, ...@@ -1121,13 +1121,16 @@ views::LabelButton* LockDebugView::AddButton(const std::string& text,
int id, int id,
views::View* container) { views::View* container) {
// Creates a button with |text| that cannot be focused. // Creates a button with |text| that cannot be focused.
auto* button = views::MdTextButton::CreateSecondaryUiButton( std::unique_ptr<views::LabelButton> button =
this, base::ASCIIToUTF16(text)) views::MdTextButton::CreateSecondaryUiButton(this,
.release(); base::ASCIIToUTF16(text));
button->SetID(id); button->SetID(id);
button->SetFocusBehavior(views::View::FocusBehavior::NEVER); button->SetFocusBehavior(views::View::FocusBehavior::NEVER);
container->AddChildView(login_views_utils::WrapViewForPreferredSize(button));
return button; views::LabelButton* view = button.get();
container->AddChildView(
login_views_utils::WrapViewForPreferredSize(std::move(button)));
return view;
} }
} // namespace ash } // namespace ash
...@@ -596,45 +596,52 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user, ...@@ -596,45 +596,52 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user,
DCHECK_NE(user.basic_user_info.type, user_manager::USER_TYPE_PUBLIC_ACCOUNT); DCHECK_NE(user.basic_user_info.type, user_manager::USER_TYPE_PUBLIC_ACCOUNT);
// Build child views. // Build child views.
user_view_ = new LoginUserView( auto user_view = std::make_unique<LoginUserView>(
LoginDisplayStyle::kLarge, true /*show_dropdown*/, false /*show_domain*/, LoginDisplayStyle::kLarge, true /*show_dropdown*/, false /*show_domain*/,
base::BindRepeating(&LoginAuthUserView::OnUserViewTap, base::BindRepeating(&LoginAuthUserView::OnUserViewTap,
base::Unretained(this)), base::Unretained(this)),
callbacks.on_remove_warning_shown, callbacks.on_remove); callbacks.on_remove_warning_shown, callbacks.on_remove);
user_view_ = user_view.get();
password_view_ = new LoginPasswordView();
password_view_->SetPaintToLayer(); // Needed for opacity animation. auto password_view = std::make_unique<LoginPasswordView>();
password_view_->layer()->SetFillsBoundsOpaquely(false); password_view_ = password_view.get();
password_view_->UpdateForUser(user); password_view->SetPaintToLayer(); // Needed for opacity animation.
password_view->layer()->SetFillsBoundsOpaquely(false);
pin_view_ = password_view->UpdateForUser(user);
new LoginPinView(LoginPinView::Style::kAlphanumeric,
base::BindRepeating(&LoginPasswordView::InsertNumber, auto pin_view = std::make_unique<LoginPinView>(
base::Unretained(password_view_)), LoginPinView::Style::kAlphanumeric,
base::BindRepeating(&LoginPasswordView::Backspace, base::BindRepeating(&LoginPasswordView::InsertNumber,
base::Unretained(password_view_))); base::Unretained(password_view.get())),
base::BindRepeating(&LoginPasswordView::Backspace,
base::Unretained(password_view.get())));
pin_view_ = pin_view.get();
DCHECK(pin_view_->layer()); DCHECK(pin_view_->layer());
padding_below_password_view_ = new NonAccessibleView(); auto padding_below_password_view = std::make_unique<NonAccessibleView>();
padding_below_password_view_->SetPreferredSize(gfx::Size( padding_below_password_view->SetPreferredSize(gfx::Size(
kNonEmptyWidthDp, kDistanceBetweenPasswordFieldAndPinKeyboardDp)); kNonEmptyWidthDp, kDistanceBetweenPasswordFieldAndPinKeyboardDp));
padding_below_password_view_ = padding_below_password_view.get();
// Initialization of |password_view_| is deferred because it needs the // Initialization of |password_view| is deferred because it needs the
// |pin_view_| pointer. // |pin_view| pointer.
password_view_->Init( password_view->Init(
base::Bind(&LoginAuthUserView::OnAuthSubmit, base::Unretained(this)), base::Bind(&LoginAuthUserView::OnAuthSubmit, base::Unretained(this)),
base::Bind(&LoginPinView::OnPasswordTextChanged, base::Bind(&LoginPinView::OnPasswordTextChanged,
base::Unretained(pin_view_)), base::Unretained(pin_view.get())),
callbacks.on_easy_unlock_icon_hovered, callbacks.on_easy_unlock_icon_hovered,
callbacks.on_easy_unlock_icon_tapped); callbacks.on_easy_unlock_icon_tapped);
online_sign_in_message_ = new views::LabelButton( auto online_sign_in_message = std::make_unique<views::LabelButton>(
this, base::UTF8ToUTF16(user.basic_user_info.display_name)); this, base::UTF8ToUTF16(user.basic_user_info.display_name));
online_sign_in_message_ = online_sign_in_message.get();
DecorateOnlineSignInMessage(online_sign_in_message_); DecorateOnlineSignInMessage(online_sign_in_message_);
disabled_auth_message_ = new DisabledAuthMessageView(); auto disabled_auth_message = std::make_unique<DisabledAuthMessageView>();
disabled_auth_message_ = disabled_auth_message.get();
fingerprint_view_ = new FingerprintView(); auto fingerprint_view = std::make_unique<FingerprintView>();
fingerprint_view_ = fingerprint_view.get();
// TODO(jdufault): Implement real UI. // TODO(jdufault): Implement real UI.
external_binary_auth_button_ = external_binary_auth_button_ =
...@@ -652,38 +659,50 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user, ...@@ -652,38 +659,50 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user,
// Wrap the password view with a fill layout so that it always consumes space, // Wrap the password view with a fill layout so that it always consumes space,
// ie, when the password view is hidden the wrapped view will still consume // ie, when the password view is hidden the wrapped view will still consume
// the same amount of space. This prevents the user view from shrinking. // the same amount of space. This prevents the user view from shrinking.
auto* wrapped_password_view = new NonAccessibleView(); auto wrapped_password_view = std::make_unique<NonAccessibleView>();
wrapped_password_view->SetLayoutManager( wrapped_password_view->SetLayoutManager(
std::make_unique<views::FillLayout>()); std::make_unique<views::FillLayout>());
wrapped_password_view->AddChildView(password_view_); wrapped_password_view->AddChildView(std::move(password_view));
auto* wrapped_online_sign_in_message_view = auto wrapped_online_sign_in_message_view =
login_views_utils::WrapViewForPreferredSize(online_sign_in_message_); login_views_utils::WrapViewForPreferredSize(
auto* wrapped_disabled_auth_message_view = std::move(online_sign_in_message));
login_views_utils::WrapViewForPreferredSize(disabled_auth_message_); auto wrapped_disabled_auth_message_view =
auto* wrapped_user_view = login_views_utils::WrapViewForPreferredSize(
login_views_utils::WrapViewForPreferredSize(user_view_); std::move(disabled_auth_message));
auto* wrapped_pin_view = auto wrapped_user_view =
login_views_utils::WrapViewForPreferredSize(pin_view_); login_views_utils::WrapViewForPreferredSize(std::move(user_view));
auto* wrapped_fingerprint_view = auto wrapped_pin_view =
login_views_utils::WrapViewForPreferredSize(fingerprint_view_); login_views_utils::WrapViewForPreferredSize(std::move(pin_view));
auto* wrapped_external_binary_view = auto wrapped_fingerprint_view =
login_views_utils::WrapViewForPreferredSize(external_binary_auth_button_); login_views_utils::WrapViewForPreferredSize(std::move(fingerprint_view));
auto* wrapped_external_binary_enrollment_view = auto wrapped_external_binary_view =
login_views_utils::WrapViewForPreferredSize(
base::WrapUnique(external_binary_auth_button_));
auto wrapped_external_binary_enrollment_view =
login_views_utils::WrapViewForPreferredSize(
base::WrapUnique(external_binary_enrollment_button_));
auto wrapped_padding_below_password_view =
login_views_utils::WrapViewForPreferredSize( login_views_utils::WrapViewForPreferredSize(
external_binary_enrollment_button_); std::move(padding_below_password_view));
auto* wrapped_padding_below_password_view =
login_views_utils::WrapViewForPreferredSize(padding_below_password_view_);
// Add views in tabbing order; they are rendered in a different order below. // Add views in tabbing order; they are rendered in a different order below.
AddChildView(wrapped_password_view); views::View* wrapped_password_view_ptr =
AddChildView(wrapped_online_sign_in_message_view); AddChildView(std::move(wrapped_password_view));
AddChildView(wrapped_disabled_auth_message_view); views::View* wrapped_online_sign_in_message_view_ptr =
AddChildView(wrapped_pin_view); AddChildView(std::move(wrapped_online_sign_in_message_view));
AddChildView(wrapped_fingerprint_view); views::View* wrapped_disabled_auth_message_view_ptr =
AddChildView(wrapped_external_binary_view); AddChildView(std::move(wrapped_disabled_auth_message_view));
AddChildView(wrapped_external_binary_enrollment_view); views::View* wrapped_pin_view_ptr = AddChildView(std::move(wrapped_pin_view));
AddChildView(wrapped_user_view); views::View* wrapped_fingerprint_view_ptr =
AddChildView(wrapped_padding_below_password_view); AddChildView(std::move(wrapped_fingerprint_view));
views::View* wrapped_external_binary_view_ptr =
AddChildView(std::move(wrapped_external_binary_view));
views::View* wrapped_external_binary_enrollment_view_ptr =
AddChildView(std::move(wrapped_external_binary_enrollment_view));
views::View* wrapped_user_view_ptr =
AddChildView(std::move(wrapped_user_view));
views::View* wrapped_padding_below_password_view_ptr =
AddChildView(std::move(wrapped_padding_below_password_view));
// Use views::GridLayout instead of views::BoxLayout because views::BoxLayout // Use views::GridLayout instead of views::BoxLayout because views::BoxLayout
// lays out children according to the view->children order. // lays out children according to the view->children order.
...@@ -703,16 +722,16 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user, ...@@ -703,16 +722,16 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user,
// Add views in rendering order. // Add views in rendering order.
add_padding(kDistanceFromTopOfBigUserViewToUserIconDp); add_padding(kDistanceFromTopOfBigUserViewToUserIconDp);
add_view(wrapped_user_view); add_view(wrapped_user_view_ptr);
add_padding(kDistanceBetweenUserViewAndPasswordDp); add_padding(kDistanceBetweenUserViewAndPasswordDp);
add_view(wrapped_password_view); add_view(wrapped_password_view_ptr);
add_view(wrapped_online_sign_in_message_view); add_view(wrapped_online_sign_in_message_view_ptr);
add_view(wrapped_disabled_auth_message_view); add_view(wrapped_disabled_auth_message_view_ptr);
add_view(wrapped_padding_below_password_view); add_view(wrapped_padding_below_password_view_ptr);
add_view(wrapped_pin_view); add_view(wrapped_pin_view_ptr);
add_view(wrapped_fingerprint_view); add_view(wrapped_fingerprint_view_ptr);
add_view(wrapped_external_binary_view); add_view(wrapped_external_binary_view_ptr);
add_view(wrapped_external_binary_enrollment_view); add_view(wrapped_external_binary_enrollment_view_ptr);
add_padding(kDistanceFromPinKeyboardToBigUserViewBottomDp); add_padding(kDistanceFromPinKeyboardToBigUserViewBottomDp);
// Update authentication UI. // Update authentication UI.
......
...@@ -68,22 +68,24 @@ LoginPublicAccountUserView::LoginPublicAccountUserView( ...@@ -68,22 +68,24 @@ LoginPublicAccountUserView::LoginPublicAccountUserView(
DCHECK(callbacks.on_tap); DCHECK(callbacks.on_tap);
DCHECK(callbacks.on_public_account_tapped); DCHECK(callbacks.on_public_account_tapped);
user_view_ = new LoginUserView( auto user_view = std::make_unique<LoginUserView>(
LoginDisplayStyle::kLarge, false /*show_dropdown*/, true /*show_domain*/, LoginDisplayStyle::kLarge, false /*show_dropdown*/, true /*show_domain*/,
base::BindRepeating(&LoginPublicAccountUserView::OnUserViewTap, base::BindRepeating(&LoginPublicAccountUserView::OnUserViewTap,
base::Unretained(this)), base::Unretained(this)),
base::RepeatingClosure(), base::RepeatingClosure()); base::RepeatingClosure(), base::RepeatingClosure());
arrow_button_ = new ArrowButtonView(this, kArrowButtonSizeDp); auto arrow_button =
arrow_button_->SetBackgroundColor(kArrowButtonBackground); std::make_unique<ArrowButtonView>(this, kArrowButtonSizeDp);
arrow_button_->SetFocusPainter(nullptr); arrow_button->SetBackgroundColor(kArrowButtonBackground);
arrow_button->SetFocusPainter(nullptr);
SetPaintToLayer(ui::LayerType::LAYER_NOT_DRAWN); SetPaintToLayer(ui::LayerType::LAYER_NOT_DRAWN);
// build layout for public account. // build layout for public account.
SetLayoutManager( SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical)); std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
views::View* wrapped_user_view = user_view_ = user_view.get();
login_views_utils::WrapViewForPreferredSize(user_view_); auto wrapped_user_view =
login_views_utils::WrapViewForPreferredSize(std::move(user_view));
auto add_padding = [&](int amount) { auto add_padding = [&](int amount) {
auto* padding = new NonAccessibleView(); auto* padding = new NonAccessibleView();
...@@ -92,9 +94,9 @@ LoginPublicAccountUserView::LoginPublicAccountUserView( ...@@ -92,9 +94,9 @@ LoginPublicAccountUserView::LoginPublicAccountUserView(
}; };
add_padding(kDistanceFromTopOfBigUserViewToUserIconDp); add_padding(kDistanceFromTopOfBigUserViewToUserIconDp);
AddChildView(wrapped_user_view); AddChildView(std::move(wrapped_user_view));
add_padding(kDistanceFromUserViewToArrowButton); add_padding(kDistanceFromUserViewToArrowButton);
AddChildView(arrow_button_); arrow_button_ = AddChildView(std::move(arrow_button));
add_padding(kDistanceFromArrowButtonToBigUserViewBottom); add_padding(kDistanceFromArrowButtonToBigUserViewBottom);
// Update authentication UI. // Update authentication UI.
......
...@@ -100,8 +100,10 @@ TEST_F(NoteActionLaunchButtonTest, VisibilityActionAvailable) { ...@@ -100,8 +100,10 @@ TEST_F(NoteActionLaunchButtonTest, VisibilityActionAvailable) {
TEST_F(NoteActionLaunchButtonTest, KeyboardTest) { TEST_F(NoteActionLaunchButtonTest, KeyboardTest) {
auto* note_action_button = auto* note_action_button =
new NoteActionLaunchButton(mojom::TrayActionState::kAvailable); new NoteActionLaunchButton(mojom::TrayActionState::kAvailable);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent( std::unique_ptr<views::Widget> widget =
login_views_utils::WrapViewForPreferredSize(note_action_button)); CreateWidgetWithContent(login_views_utils::WrapViewForPreferredSize(
base::WrapUnique(note_action_button))
.release());
NoteActionLaunchButton::TestApi test_api(note_action_button); NoteActionLaunchButton::TestApi test_api(note_action_button);
note_action_button->RequestFocus(); note_action_button->RequestFocus();
...@@ -125,8 +127,10 @@ TEST_F(NoteActionLaunchButtonTest, KeyboardTest) { ...@@ -125,8 +127,10 @@ TEST_F(NoteActionLaunchButtonTest, KeyboardTest) {
TEST_F(NoteActionLaunchButtonTest, ClickTest) { TEST_F(NoteActionLaunchButtonTest, ClickTest) {
auto* note_action_button = auto* note_action_button =
new NoteActionLaunchButton(mojom::TrayActionState::kAvailable); new NoteActionLaunchButton(mojom::TrayActionState::kAvailable);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent( std::unique_ptr<views::Widget> widget =
login_views_utils::WrapViewForPreferredSize(note_action_button)); CreateWidgetWithContent(login_views_utils::WrapViewForPreferredSize(
base::WrapUnique(note_action_button))
.release());
const gfx::Size action_size = note_action_button->GetPreferredSize(); const gfx::Size action_size = note_action_button->GetPreferredSize();
EXPECT_EQ(gfx::Size(kLargeButtonRadiusDp, kLargeButtonRadiusDp), action_size); EXPECT_EQ(gfx::Size(kLargeButtonRadiusDp, kLargeButtonRadiusDp), action_size);
...@@ -237,8 +241,10 @@ TEST_F(NoteActionLaunchButtonTest, ClickTest) { ...@@ -237,8 +241,10 @@ TEST_F(NoteActionLaunchButtonTest, ClickTest) {
TEST_F(NoteActionLaunchButtonTest, TapTest) { TEST_F(NoteActionLaunchButtonTest, TapTest) {
auto* note_action_button = auto* note_action_button =
new NoteActionLaunchButton(mojom::TrayActionState::kAvailable); new NoteActionLaunchButton(mojom::TrayActionState::kAvailable);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent( std::unique_ptr<views::Widget> widget =
login_views_utils::WrapViewForPreferredSize(note_action_button)); CreateWidgetWithContent(login_views_utils::WrapViewForPreferredSize(
base::WrapUnique(note_action_button))
.release());
const gfx::Size action_size = note_action_button->GetPreferredSize(); const gfx::Size action_size = note_action_button->GetPreferredSize();
EXPECT_EQ(gfx::Size(kLargeButtonRadiusDp, kLargeButtonRadiusDp), action_size); EXPECT_EQ(gfx::Size(kLargeButtonRadiusDp, kLargeButtonRadiusDp), action_size);
...@@ -272,8 +278,10 @@ TEST_F(NoteActionLaunchButtonTest, TapTest) { ...@@ -272,8 +278,10 @@ TEST_F(NoteActionLaunchButtonTest, TapTest) {
TEST_F(NoteActionLaunchButtonTest, FlingGesture) { TEST_F(NoteActionLaunchButtonTest, FlingGesture) {
auto* note_action_button = auto* note_action_button =
new NoteActionLaunchButton(mojom::TrayActionState::kAvailable); new NoteActionLaunchButton(mojom::TrayActionState::kAvailable);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent( std::unique_ptr<views::Widget> widget =
login_views_utils::WrapViewForPreferredSize(note_action_button)); CreateWidgetWithContent(login_views_utils::WrapViewForPreferredSize(
base::WrapUnique(note_action_button))
.release());
const gfx::Size action_size = note_action_button->GetPreferredSize(); const gfx::Size action_size = note_action_button->GetPreferredSize();
EXPECT_EQ(gfx::Size(kLargeButtonRadiusDp, kLargeButtonRadiusDp), action_size); EXPECT_EQ(gfx::Size(kLargeButtonRadiusDp, kLargeButtonRadiusDp), action_size);
...@@ -326,8 +334,10 @@ TEST_F(NoteActionLaunchButtonTest, FlingGesture) { ...@@ -326,8 +334,10 @@ TEST_F(NoteActionLaunchButtonTest, FlingGesture) {
TEST_F(NoteActionLaunchButtonTest, MultiFingerFling) { TEST_F(NoteActionLaunchButtonTest, MultiFingerFling) {
auto* note_action_button = auto* note_action_button =
new NoteActionLaunchButton(mojom::TrayActionState::kAvailable); new NoteActionLaunchButton(mojom::TrayActionState::kAvailable);
std::unique_ptr<views::Widget> widget = CreateWidgetWithContent( std::unique_ptr<views::Widget> widget =
login_views_utils::WrapViewForPreferredSize(note_action_button)); CreateWidgetWithContent(login_views_utils::WrapViewForPreferredSize(
base::WrapUnique(note_action_button))
.release());
const gfx::Size action_size = note_action_button->GetPreferredSize(); const gfx::Size action_size = note_action_button->GetPreferredSize();
EXPECT_EQ(gfx::Size(kLargeButtonRadiusDp, kLargeButtonRadiusDp), action_size); EXPECT_EQ(gfx::Size(kLargeButtonRadiusDp, kLargeButtonRadiusDp), action_size);
......
...@@ -13,14 +13,15 @@ ...@@ -13,14 +13,15 @@
namespace ash { namespace ash {
namespace login_views_utils { namespace login_views_utils {
views::View* WrapViewForPreferredSize(views::View* view) { std::unique_ptr<views::View> WrapViewForPreferredSize(
auto* proxy = new NonAccessibleView(); std::unique_ptr<views::View> view) {
auto proxy = std::make_unique<NonAccessibleView>();
auto layout_manager = auto layout_manager =
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical); std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical);
layout_manager->set_cross_axis_alignment( layout_manager->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kStart); views::BoxLayout::CrossAxisAlignment::kStart);
proxy->SetLayoutManager(std::move(layout_manager)); proxy->SetLayoutManager(std::move(layout_manager));
proxy->AddChildView(view); proxy->AddChildView(std::move(view));
return proxy; return proxy;
} }
......
...@@ -19,7 +19,8 @@ namespace login_views_utils { ...@@ -19,7 +19,8 @@ namespace login_views_utils {
// Wraps view in another view so the original view is sized to it's preferred // Wraps view in another view so the original view is sized to it's preferred
// size, regardless of the view's parent's layout manager. // size, regardless of the view's parent's layout manager.
ASH_EXPORT views::View* WrapViewForPreferredSize(views::View* view); ASH_EXPORT std::unique_ptr<views::View> WrapViewForPreferredSize(
std::unique_ptr<views::View> view);
// Returns true if landscape constants should be used for UI shown in |widget|. // Returns true if landscape constants should be used for UI shown in |widget|.
ASH_EXPORT bool ShouldShowLandscape(const views::Widget* widget); ASH_EXPORT bool ShouldShowLandscape(const views::Widget* widget);
......
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