Commit 1ce1a483 authored by Megumi Hattori's avatar Megumi Hattori Committed by Commit Bot

Always change reply button color when textfield become empty or not.

The reply button should be white when the textfield is not empty, and should be transparent white when the textfield is empty.
However, when text is cut or pasted using mouse or finger and the textfield become empty or not, the reply button color does not change.
This CL resolved this bug.

Bug=803759

Change-Id: Ie307a924b41bddc88f60d9dc1b7ab230e639e0c7
Reviewed-on: https://chromium-review.googlesource.com/890843
Commit-Queue: Megumi Hattori <megumihattori@google.com>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533187}
parent 877ca101
...@@ -370,9 +370,9 @@ NotificationButtonMD::CreateInkDropHighlight() const { ...@@ -370,9 +370,9 @@ NotificationButtonMD::CreateInkDropHighlight() const {
// NotificationInputTextfieldMD //////////////////////////////////////////////// // NotificationInputTextfieldMD ////////////////////////////////////////////////
NotificationInputTextfieldMD::NotificationInputTextfieldMD( NotificationInputTextfieldMD::NotificationInputTextfieldMD(
NotificationInputDelegate* delegate) views::TextfieldController* controller)
: delegate_(delegate), index_(0) { : index_(0) {
set_controller(this); set_controller(controller);
SetTextColor(kInputTextColor); SetTextColor(kInputTextColor);
SetBackgroundColor(SK_ColorTRANSPARENT); SetBackgroundColor(SK_ColorTRANSPARENT);
set_placeholder_text_color(kInputPlaceholderColor); set_placeholder_text_color(kInputPlaceholderColor);
...@@ -381,41 +381,6 @@ NotificationInputTextfieldMD::NotificationInputTextfieldMD( ...@@ -381,41 +381,6 @@ NotificationInputTextfieldMD::NotificationInputTextfieldMD(
NotificationInputTextfieldMD::~NotificationInputTextfieldMD() = default; NotificationInputTextfieldMD::~NotificationInputTextfieldMD() = default;
void NotificationInputTextfieldMD::CheckUpdateImage() {
if (is_empty_ && !text().empty()) {
is_empty_ = false;
delegate_->SetNormalImageToReplyButton();
} else if (!is_empty_ && text().empty()) {
is_empty_ = true;
delegate_->SetPlaceholderImageToReplyButton();
}
}
bool NotificationInputTextfieldMD::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& event) {
CheckUpdateImage();
if (event.type() == ui::ET_KEY_PRESSED &&
event.key_code() == ui::VKEY_RETURN) {
delegate_->OnNotificationInputSubmit(index_, text());
return true;
}
return event.type() == ui::ET_KEY_RELEASED;
}
bool NotificationInputTextfieldMD::HandleMouseEvent(
views::Textfield* sender,
const ui::MouseEvent& event) {
CheckUpdateImage();
return event.type() == ui::ET_MOUSE_RELEASED;
}
bool NotificationInputTextfieldMD::HandleGestureEvent(
views::Textfield* sender,
const ui::GestureEvent& event) {
CheckUpdateImage();
return false;
}
void NotificationInputTextfieldMD::set_placeholder( void NotificationInputTextfieldMD::set_placeholder(
const base::string16& placeholder) { const base::string16& placeholder) {
if (placeholder.empty()) { if (placeholder.empty()) {
...@@ -457,7 +422,7 @@ NotificationInputContainerMD::NotificationInputContainerMD( ...@@ -457,7 +422,7 @@ NotificationInputContainerMD::NotificationInputContainerMD(
NotificationInputDelegate* delegate) NotificationInputDelegate* delegate)
: delegate_(delegate), : delegate_(delegate),
ink_drop_container_(new views::InkDropContainerView()), ink_drop_container_(new views::InkDropContainerView()),
textfield_(new NotificationInputTextfieldMD(delegate)), textfield_(new NotificationInputTextfieldMD(this)),
button_(new NotificationInputReplyButtonMD(this)) { button_(new NotificationInputReplyButtonMD(this)) {
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>( auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kHorizontal, gfx::Insets(), 0)); views::BoxLayout::kHorizontal, gfx::Insets(), 0));
...@@ -513,6 +478,25 @@ SkColor NotificationInputContainerMD::GetInkDropBaseColor() const { ...@@ -513,6 +478,25 @@ SkColor NotificationInputContainerMD::GetInkDropBaseColor() const {
return kInputContainerBackgroundColor; return kInputContainerBackgroundColor;
} }
bool NotificationInputContainerMD::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& event) {
if (event.type() == ui::ET_KEY_PRESSED &&
event.key_code() == ui::VKEY_RETURN) {
delegate_->OnNotificationInputSubmit(textfield_->index(),
textfield_->text());
return true;
}
return event.type() == ui::ET_KEY_RELEASED;
}
void NotificationInputContainerMD::OnAfterUserAction(views::Textfield* sender) {
if (textfield_->text().empty()) {
button_->SetPlaceholderImage();
} else {
button_->SetNormalImage();
}
}
void NotificationInputContainerMD::ButtonPressed(views::Button* sender, void NotificationInputContainerMD::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
if (sender == button_) { if (sender == button_) {
...@@ -823,14 +807,6 @@ void NotificationViewMD::ButtonPressed(views::Button* sender, ...@@ -823,14 +807,6 @@ void NotificationViewMD::ButtonPressed(views::Button* sender,
} }
} }
void NotificationViewMD::SetNormalImageToReplyButton() {
inline_reply_->button()->SetNormalImage();
}
void NotificationViewMD::SetPlaceholderImageToReplyButton() {
inline_reply_->button()->SetPlaceholderImage();
}
void NotificationViewMD::OnNotificationInputSubmit(size_t index, void NotificationViewMD::OnNotificationInputSubmit(size_t index,
const base::string16& text) { const base::string16& text) {
MessageCenter::Get()->ClickOnNotificationButtonWithReply(notification_id(), MessageCenter::Get()->ClickOnNotificationButtonWithReply(notification_id(),
......
...@@ -139,37 +139,22 @@ class NotificationButtonMD : public views::LabelButton { ...@@ -139,37 +139,22 @@ class NotificationButtonMD : public views::LabelButton {
class NotificationInputDelegate { class NotificationInputDelegate {
public: public:
virtual void SetNormalImageToReplyButton() = 0;
virtual void SetPlaceholderImageToReplyButton() = 0;
virtual void OnNotificationInputSubmit(size_t index, virtual void OnNotificationInputSubmit(size_t index,
const base::string16& text) = 0; const base::string16& text) = 0;
virtual ~NotificationInputDelegate() = default; virtual ~NotificationInputDelegate() = default;
}; };
class NotificationInputTextfieldMD : public views::Textfield, class NotificationInputTextfieldMD : public views::Textfield {
public views::TextfieldController {
public: public:
NotificationInputTextfieldMD(NotificationInputDelegate* delegate); NotificationInputTextfieldMD(views::TextfieldController* controller);
~NotificationInputTextfieldMD() override; ~NotificationInputTextfieldMD() override;
void CheckUpdateImage();
bool HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) override;
bool HandleMouseEvent(views::Textfield* sender,
const ui::MouseEvent& mouse_event) override;
bool HandleGestureEvent(views::Textfield* sender,
const ui::GestureEvent& gesture_event) override;
void set_index(size_t index) { index_ = index; } void set_index(size_t index) { index_ = index; }
void set_placeholder(const base::string16& placeholder); void set_placeholder(const base::string16& placeholder);
size_t index() const { return index_; }; size_t index() const { return index_; };
private: private:
NotificationInputDelegate* const delegate_;
bool is_empty_ = true;
// |index_| is the notification action index that should be passed as the // |index_| is the notification action index that should be passed as the
// argument of ClickOnNotificationButtonWithReply. // argument of ClickOnNotificationButtonWithReply.
size_t index_ = 0; size_t index_ = 0;
...@@ -190,7 +175,8 @@ class NotificationInputReplyButtonMD : public views::ImageButton { ...@@ -190,7 +175,8 @@ class NotificationInputReplyButtonMD : public views::ImageButton {
}; };
class NotificationInputContainerMD : public views::InkDropHostView, class NotificationInputContainerMD : public views::InkDropHostView,
public views::ButtonListener { public views::ButtonListener,
public views::TextfieldController {
public: public:
NotificationInputContainerMD(NotificationInputDelegate* delegate); NotificationInputContainerMD(NotificationInputDelegate* delegate);
~NotificationInputContainerMD() override; ~NotificationInputContainerMD() override;
...@@ -203,6 +189,11 @@ class NotificationInputContainerMD : public views::InkDropHostView, ...@@ -203,6 +189,11 @@ class NotificationInputContainerMD : public views::InkDropHostView,
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
SkColor GetInkDropBaseColor() const override; SkColor GetInkDropBaseColor() const override;
// Overridden from views::TextfieldController:
bool HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) override;
void OnAfterUserAction(views::Textfield* sender) override;
// Overridden from views::ButtonListener: // Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
...@@ -256,8 +247,6 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD ...@@ -256,8 +247,6 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD
void OnSettingsButtonPressed() override; void OnSettingsButtonPressed() override;
// Overridden from NotificationInputDelegate: // Overridden from NotificationInputDelegate:
void SetNormalImageToReplyButton() override;
void SetPlaceholderImageToReplyButton() override;
void OnNotificationInputSubmit(size_t index, void OnNotificationInputSubmit(size_t index,
const base::string16& text) override; const base::string16& text) override;
......
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