Commit 0ac4fa20 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Get rid of message_center::ButtonType enum.

Intuit the button type from the presence or absence of the placeholder
text.

Bug: 797128
Change-Id: I6fe658f644e42b0556ffcaac9bc7322f44f88fea
Reviewed-on: https://chromium-review.googlesource.com/900184Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534704}
parent 4bf3f745
...@@ -67,14 +67,8 @@ ScopedJavaLocalRef<jobject> JNI_NotificationPlatformBridge_ConvertToJavaBitmap( ...@@ -67,14 +67,8 @@ ScopedJavaLocalRef<jobject> JNI_NotificationPlatformBridge_ConvertToJavaBitmap(
NotificationActionType GetNotificationActionType( NotificationActionType GetNotificationActionType(
message_center::ButtonInfo button) { message_center::ButtonInfo button) {
switch (button.type) { return button.placeholder ? NotificationActionType::TEXT
case message_center::ButtonType::BUTTON: : NotificationActionType::BUTTON;
return NotificationActionType::BUTTON;
case message_center::ButtonType::TEXT:
return NotificationActionType::TEXT;
}
NOTREACHED();
return NotificationActionType::TEXT;
} }
ScopedJavaLocalRef<jobjectArray> ConvertToJavaActionInfos( ScopedJavaLocalRef<jobjectArray> ConvertToJavaActionInfos(
...@@ -91,8 +85,11 @@ ScopedJavaLocalRef<jobjectArray> ConvertToJavaActionInfos( ...@@ -91,8 +85,11 @@ ScopedJavaLocalRef<jobjectArray> ConvertToJavaActionInfos(
ScopedJavaLocalRef<jstring> title = ScopedJavaLocalRef<jstring> title =
base::android::ConvertUTF16ToJavaString(env, button.title); base::android::ConvertUTF16ToJavaString(env, button.title);
int type = GetNotificationActionType(button); int type = GetNotificationActionType(button);
ScopedJavaLocalRef<jstring> placeholder = ScopedJavaLocalRef<jstring> placeholder;
base::android::ConvertUTF16ToJavaString(env, button.placeholder); if (button.placeholder) {
placeholder =
base::android::ConvertUTF16ToJavaString(env, *button.placeholder);
}
ScopedJavaLocalRef<jobject> icon = ScopedJavaLocalRef<jobject> icon =
JNI_NotificationPlatformBridge_ConvertToJavaBitmap(env, button.icon); JNI_NotificationPlatformBridge_ConvertToJavaBitmap(env, button.icon);
ScopedJavaLocalRef<jobject> action_info = Java_ActionInfo_createActionInfo( ScopedJavaLocalRef<jobject> action_info = Java_ActionInfo_createActionInfo(
......
...@@ -295,11 +295,11 @@ void NotificationTemplateBuilder::AddActions( ...@@ -295,11 +295,11 @@ void NotificationTemplateBuilder::AddActions(
bool inline_reply = false; bool inline_reply = false;
std::string placeholder; std::string placeholder;
for (const auto& button : buttons) { for (const auto& button : buttons) {
if (button.type != message_center::ButtonType::TEXT) if (!button.placeholder)
continue; continue;
inline_reply = true; inline_reply = true;
placeholder = base::UTF16ToUTF8(button.placeholder); placeholder = base::UTF16ToUTF8(*button.placeholder);
break; break;
} }
......
...@@ -155,7 +155,6 @@ TEST_F(NotificationTemplateBuilderTest, InlineReplies) { ...@@ -155,7 +155,6 @@ TEST_F(NotificationTemplateBuilderTest, InlineReplies) {
std::vector<message_center::ButtonInfo> buttons; std::vector<message_center::ButtonInfo> buttons;
message_center::ButtonInfo button1(base::ASCIIToUTF16("Button1")); message_center::ButtonInfo button1(base::ASCIIToUTF16("Button1"));
button1.type = message_center::ButtonType::TEXT;
button1.placeholder = base::ASCIIToUTF16("Reply here"); button1.placeholder = base::ASCIIToUTF16("Reply here");
buttons.emplace_back(button1); buttons.emplace_back(button1);
buttons.emplace_back(base::ASCIIToUTF16("Button2")); buttons.emplace_back(base::ASCIIToUTF16("Button2"));
...@@ -188,11 +187,9 @@ TEST_F(NotificationTemplateBuilderTest, InlineRepliesDoubleInput) { ...@@ -188,11 +187,9 @@ TEST_F(NotificationTemplateBuilderTest, InlineRepliesDoubleInput) {
std::vector<message_center::ButtonInfo> buttons; std::vector<message_center::ButtonInfo> buttons;
message_center::ButtonInfo button1(base::ASCIIToUTF16("Button1")); message_center::ButtonInfo button1(base::ASCIIToUTF16("Button1"));
button1.type = message_center::ButtonType::TEXT;
button1.placeholder = base::ASCIIToUTF16("Reply here"); button1.placeholder = base::ASCIIToUTF16("Reply here");
buttons.emplace_back(button1); buttons.emplace_back(button1);
message_center::ButtonInfo button2(base::ASCIIToUTF16("Button2")); message_center::ButtonInfo button2(base::ASCIIToUTF16("Button2"));
button2.type = message_center::ButtonType::TEXT;
button2.placeholder = base::ASCIIToUTF16("Should not appear"); button2.placeholder = base::ASCIIToUTF16("Should not appear");
buttons.emplace_back(button2); buttons.emplace_back(button2);
notification->set_buttons(buttons); notification->set_buttons(buttons);
...@@ -225,7 +222,6 @@ TEST_F(NotificationTemplateBuilderTest, InlineRepliesTextTypeNotFirst) { ...@@ -225,7 +222,6 @@ TEST_F(NotificationTemplateBuilderTest, InlineRepliesTextTypeNotFirst) {
std::vector<message_center::ButtonInfo> buttons; std::vector<message_center::ButtonInfo> buttons;
buttons.emplace_back(base::ASCIIToUTF16("Button1")); buttons.emplace_back(base::ASCIIToUTF16("Button1"));
message_center::ButtonInfo button2(base::ASCIIToUTF16("Button2")); message_center::ButtonInfo button2(base::ASCIIToUTF16("Button2"));
button2.type = message_center::ButtonType::TEXT;
button2.placeholder = base::ASCIIToUTF16("Reply here"); button2.placeholder = base::ASCIIToUTF16("Reply here");
buttons.emplace_back(button2); buttons.emplace_back(button2);
notification->set_buttons(buttons); notification->set_buttons(buttons);
...@@ -369,7 +365,6 @@ TEST_F(NotificationTemplateBuilderTest, Images) { ...@@ -369,7 +365,6 @@ TEST_F(NotificationTemplateBuilderTest, Images) {
std::vector<message_center::ButtonInfo> buttons; std::vector<message_center::ButtonInfo> buttons;
message_center::ButtonInfo button(base::ASCIIToUTF16("Button1")); message_center::ButtonInfo button(base::ASCIIToUTF16("Button1"));
button.type = message_center::ButtonType::TEXT;
button.placeholder = base::ASCIIToUTF16("Reply here"); button.placeholder = base::ASCIIToUTF16("Reply here");
button.icon = gfx::Image::CreateFrom1xBitmap(icon); button.icon = gfx::Image::CreateFrom1xBitmap(icon);
buttons.emplace_back(button); buttons.emplace_back(button);
......
...@@ -540,17 +540,9 @@ PlatformNotificationServiceImpl::CreateNotificationFromData( ...@@ -540,17 +540,9 @@ PlatformNotificationServiceImpl::CreateNotificationFromData(
// the 1x bitmap - crbug.com/585815. // the 1x bitmap - crbug.com/585815.
button.icon = button.icon =
gfx::Image::CreateFrom1xBitmap(notification_resources.action_icons[i]); gfx::Image::CreateFrom1xBitmap(notification_resources.action_icons[i]);
button.placeholder = if (action.type == content::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT) {
action.placeholder.is_null() button.placeholder = action.placeholder.as_optional_string16().value_or(
? l10n_util::GetStringUTF16(IDS_NOTIFICATION_REPLY_PLACEHOLDER) l10n_util::GetStringUTF16(IDS_NOTIFICATION_REPLY_PLACEHOLDER));
: action.placeholder.string();
switch (action.type) {
case content::PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON:
button.type = message_center::ButtonType::BUTTON;
break;
case content::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT:
button.type = message_center::ButtonType::TEXT;
break;
} }
buttons.push_back(button); buttons.push_back(button);
} }
......
...@@ -247,9 +247,9 @@ TEST_F(PlatformNotificationServiceTest, DisplayPersistentPropertiesMatch) { ...@@ -247,9 +247,9 @@ TEST_F(PlatformNotificationServiceTest, DisplayPersistentPropertiesMatch) {
const auto& buttons = notification.buttons(); const auto& buttons = notification.buttons();
ASSERT_EQ(2u, buttons.size()); ASSERT_EQ(2u, buttons.size());
EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title)); EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title));
EXPECT_EQ(message_center::ButtonType::BUTTON, buttons[0].type); EXPECT_FALSE(buttons[0].placeholder);
EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title)); EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title));
EXPECT_EQ(message_center::ButtonType::TEXT, buttons[1].type); EXPECT_TRUE(buttons[1].placeholder);
} }
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
...@@ -45,15 +46,6 @@ struct MESSAGE_CENTER_PUBLIC_EXPORT NotificationItem { ...@@ -45,15 +46,6 @@ struct MESSAGE_CENTER_PUBLIC_EXPORT NotificationItem {
base::string16 message; base::string16 message;
}; };
enum class ButtonType {
// A simple button having an icon and a title that the user can click on.
BUTTON,
// A button having an icon and a title that should also enable the user to
// input text, enabling them to quickly respond from the notification.
TEXT
};
enum class SettingsButtonHandler { enum class SettingsButtonHandler {
NONE, // No button. This is the default. NONE, // No button. This is the default.
TRAY, // Button shown, the tray handles clicks. Only used on Chrome OS. TRAY, // Button shown, the tray handles clicks. Only used on Chrome OS.
...@@ -77,12 +69,10 @@ struct MESSAGE_CENTER_PUBLIC_EXPORT ButtonInfo { ...@@ -77,12 +69,10 @@ struct MESSAGE_CENTER_PUBLIC_EXPORT ButtonInfo {
// requirements of the notification. // requirements of the notification.
gfx::Image icon; gfx::Image icon;
// Type of this button. // The placeholder string that should be displayed in the input field for
ButtonType type = ButtonType::BUTTON; // text input type buttons until the user has entered a response themselves.
// If the value is null, there is no input field associated with the button.
// The placeholder string that should be displayed in the input field for TEXT base::Optional<base::string16> placeholder;
// type buttons until the user has entered a response themselves.
base::string16 placeholder;
}; };
// TODO(estade): add an ALWAYS value to mark notifications as additionally // TODO(estade): add an ALWAYS value to mark notifications as additionally
......
...@@ -329,14 +329,13 @@ const char* LargeImageContainerView::GetClassName() const { ...@@ -329,14 +329,13 @@ const char* LargeImageContainerView::GetClassName() const {
// NotificationButtonMD //////////////////////////////////////////////////////// // NotificationButtonMD ////////////////////////////////////////////////////////
NotificationButtonMD::NotificationButtonMD(views::ButtonListener* listener, NotificationButtonMD::NotificationButtonMD(
bool is_inline_reply, views::ButtonListener* listener,
const base::string16& label, const base::string16& label,
const base::string16& placeholder) const base::Optional<base::string16>& placeholder)
: views::LabelButton(listener, : views::LabelButton(listener,
base::i18n::ToUpper(label), base::i18n::ToUpper(label),
views::style::CONTEXT_BUTTON_MD), views::style::CONTEXT_BUTTON_MD),
is_inline_reply_(is_inline_reply),
placeholder_(placeholder) { placeholder_(placeholder) {
SetHorizontalAlignment(gfx::ALIGN_CENTER); SetHorizontalAlignment(gfx::ALIGN_CENTER);
SetInkDropMode(views::LabelButton::InkDropMode::ON); SetInkDropMode(views::LabelButton::InkDropMode::ON);
...@@ -783,10 +782,10 @@ void NotificationViewMD::ButtonPressed(views::Button* sender, ...@@ -783,10 +782,10 @@ void NotificationViewMD::ButtonPressed(views::Button* sender,
for (size_t i = 0; i < action_buttons_.size(); ++i) { for (size_t i = 0; i < action_buttons_.size(); ++i) {
if (sender != action_buttons_[i]) if (sender != action_buttons_[i])
continue; continue;
if (action_buttons_[i]->is_inline_reply()) { if (action_buttons_[i]->placeholder()) {
inline_reply_->textfield()->set_index(i); inline_reply_->textfield()->set_index(i);
inline_reply_->textfield()->set_placeholder( inline_reply_->textfield()->set_placeholder(
action_buttons_[i]->placeholder()); *action_buttons_[i]->placeholder());
inline_reply_->textfield()->RequestFocus(); inline_reply_->textfield()->RequestFocus();
inline_reply_->AnimateBackground(*event.AsLocatedEvent()); inline_reply_->AnimateBackground(*event.AsLocatedEvent());
inline_reply_->SetVisible(true); inline_reply_->SetVisible(true);
...@@ -1048,7 +1047,7 @@ void NotificationViewMD::CreateOrUpdateImageView( ...@@ -1048,7 +1047,7 @@ void NotificationViewMD::CreateOrUpdateImageView(
void NotificationViewMD::CreateOrUpdateActionButtonViews( void NotificationViewMD::CreateOrUpdateActionButtonViews(
const Notification& notification) { const Notification& notification) {
std::vector<ButtonInfo> buttons = notification.buttons(); const std::vector<ButtonInfo>& buttons = notification.buttons();
bool new_buttons = action_buttons_.size() != buttons.size(); bool new_buttons = action_buttons_.size() != buttons.size();
if (new_buttons || buttons.size() == 0) { if (new_buttons || buttons.size() == 0) {
...@@ -1062,9 +1061,8 @@ void NotificationViewMD::CreateOrUpdateActionButtonViews( ...@@ -1062,9 +1061,8 @@ void NotificationViewMD::CreateOrUpdateActionButtonViews(
for (size_t i = 0; i < buttons.size(); ++i) { for (size_t i = 0; i < buttons.size(); ++i) {
ButtonInfo button_info = buttons[i]; ButtonInfo button_info = buttons[i];
if (new_buttons) { if (new_buttons) {
bool is_inline_reply = button_info.type == ButtonType::TEXT;
NotificationButtonMD* button = new NotificationButtonMD( NotificationButtonMD* button = new NotificationButtonMD(
this, is_inline_reply, button_info.title, button_info.placeholder); this, button_info.title, button_info.placeholder);
action_buttons_.push_back(button); action_buttons_.push_back(button);
action_buttons_row_->AddChildView(button); action_buttons_row_->AddChildView(button);
} else { } else {
...@@ -1130,8 +1128,8 @@ void NotificationViewMD::CreateOrUpdateInlineSettingsViews( ...@@ -1130,8 +1128,8 @@ void NotificationViewMD::CreateOrUpdateInlineSettingsViews(
settings_row_->SetVisible(false); settings_row_->SetVisible(false);
settings_done_button_ = new NotificationButtonMD( settings_done_button_ = new NotificationButtonMD(
this, false, l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS_DONE), this, l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS_DONE),
base::EmptyString16()); base::nullopt);
auto* settings_button_row = new views::View; auto* settings_button_row = new views::View;
auto settings_button_layout = std::make_unique<views::BoxLayout>( auto settings_button_layout = std::make_unique<views::BoxLayout>(
views::BoxLayout::kHorizontal, kSettingsButtonRowPadding, 0); views::BoxLayout::kHorizontal, kSettingsButtonRowPadding, 0);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "ui/message_center/message_center_export.h" #include "ui/message_center/message_center_export.h"
#include "ui/message_center/views/message_view.h" #include "ui/message_center/views/message_view.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
...@@ -114,9 +115,8 @@ class NotificationButtonMD : public views::LabelButton { ...@@ -114,9 +115,8 @@ class NotificationButtonMD : public views::LabelButton {
// |placeholder| is placeholder text shown on the input field. Only used when // |placeholder| is placeholder text shown on the input field. Only used when
// |is_inline_reply| is true. // |is_inline_reply| is true.
NotificationButtonMD(views::ButtonListener* listener, NotificationButtonMD(views::ButtonListener* listener,
bool is_inline_reply,
const base::string16& label, const base::string16& label,
const base::string16& placeholder); const base::Optional<base::string16>& placeholder);
~NotificationButtonMD() override; ~NotificationButtonMD() override;
void SetText(const base::string16& text) override; void SetText(const base::string16& text) override;
...@@ -127,12 +127,12 @@ class NotificationButtonMD : public views::LabelButton { ...@@ -127,12 +127,12 @@ class NotificationButtonMD : public views::LabelButton {
SkColor enabled_color_for_testing() { return label()->enabled_color(); } SkColor enabled_color_for_testing() { return label()->enabled_color(); }
bool is_inline_reply() const { return is_inline_reply_; } const base::Optional<base::string16>& placeholder() const {
const base::string16& placeholder() const { return placeholder_; } return placeholder_;
}
private: private:
const bool is_inline_reply_; const base::Optional<base::string16> placeholder_;
const base::string16 placeholder_;
DISALLOW_COPY_AND_ASSIGN(NotificationButtonMD); DISALLOW_COPY_AND_ASSIGN(NotificationButtonMD);
}; };
......
...@@ -472,7 +472,7 @@ TEST_F(NotificationViewMDTest, TestInlineReply) { ...@@ -472,7 +472,7 @@ TEST_F(NotificationViewMDTest, TestInlineReply) {
delegate_->set_expecting_reply_submission(true); delegate_->set_expecting_reply_submission(true);
std::vector<ButtonInfo> buttons = CreateButtons(2); std::vector<ButtonInfo> buttons = CreateButtons(2);
buttons[1].type = ButtonType::TEXT; buttons[1].placeholder = base::string16();
notification()->set_buttons(buttons); notification()->set_buttons(buttons);
UpdateNotificationViews(); UpdateNotificationViews();
widget()->Show(); widget()->Show();
......
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