Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Unified Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 2973463002: MacViews: Don't InsertChar() for consumed events. (Closed)
Patch Set: Rebase (patch failure due to r484422) Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/textfield/textfield_unittest.cc
diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc
index f26f972ed37cd4953f65e6c61879b64c5767a3a4..7b49cf54c3d41eb75d1ac1df23becb4b2fae7222 100644
--- a/ui/views/controls/textfield/textfield_unittest.cc
+++ b/ui/views/controls/textfield/textfield_unittest.cc
@@ -182,7 +182,7 @@ ui::EventDispatchDetails MockInputMethod::DispatchKeyEvent(ui::KeyEvent* key) {
dispatch_details = DispatchKeyEventPostIME(key);
}
- if (dispatch_details.dispatcher_destroyed)
+ if (key->handled() || dispatch_details.dispatcher_destroyed)
return dispatch_details;
ui::TextInputClient* client = GetTextInputClient();
@@ -348,6 +348,29 @@ class TextfieldDestroyerController : public views::TextfieldController {
std::unique_ptr<views::Textfield> target_;
};
+// Class that focuses a textfield when it sees a KeyDown event.
+class TextfieldFocuser : public views::View {
+ public:
+ explicit TextfieldFocuser(views::Textfield* textfield)
+ : textfield_(textfield) {
+ SetFocusBehavior(FocusBehavior::ALWAYS);
+ }
+
+ void set_consume(bool consume) { consume_ = consume; }
+
+ // View:
+ bool OnKeyPressed(const ui::KeyEvent& event) override {
+ textfield_->RequestFocus();
+ return consume_;
+ }
+
+ private:
+ bool consume_ = true;
+ views::Textfield* textfield_;
+
+ DISALLOW_COPY_AND_ASSIGN(TextfieldFocuser);
+};
+
base::string16 GetClipboardText(ui::ClipboardType type) {
base::string16 text;
ui::Clipboard::GetForCurrentThread()->ReadText(type, &text);
@@ -3200,4 +3223,25 @@ TEST_F(TextfieldTest, TextfieldBoundsChangeTest) {
EXPECT_GT(prev_x, GetCursorBounds().x());
}
+// Verify that if a textfield gains focus during key dispatch that an edit
+// command only results when the event is not consumed.
+TEST_F(TextfieldTest, SwitchFocusInKeyDown) {
+ InitTextfield();
+ TextfieldFocuser* focuser = new TextfieldFocuser(textfield_);
+ widget_->GetContentsView()->AddChildView(focuser);
+
+ focuser->RequestFocus();
+ EXPECT_EQ(focuser, GetFocusedView());
+ SendKeyPress(ui::VKEY_SPACE, 0);
+ EXPECT_EQ(textfield_, GetFocusedView());
+ EXPECT_EQ(base::string16(), textfield_->text());
+
+ focuser->set_consume(false);
+ focuser->RequestFocus();
+ EXPECT_EQ(focuser, GetFocusedView());
+ SendKeyPress(ui::VKEY_SPACE, 0);
+ EXPECT_EQ(textfield_, GetFocusedView());
+ EXPECT_EQ(base::ASCIIToUTF16(" "), textfield_->text());
+}
+
} // namespace views
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698