Skip to content

Commit

Permalink
Don't show text selection popup menu if current selected text is clea…
Browse files Browse the repository at this point in the history
…red.

If text selection clear action is just after selecting all text action in editable input box,
then the state of text selection in renderer is not correct, which causes the selection popup
menu will be incorrectly shown.
Fix this issue by checking selection state before popup text selection menu.

Bug: 817712

Change-Id: I4dcda47d5f0fe5f20febc2e1def30574c6060724
Reviewed-on: https://chromium-review.googlesource.com/940290
Commit-Queue: Antoine Labour <piman@chromium.org>
Reviewed-by: Changwan Ryu <changwan@chromium.org>
Reviewed-by: Pedro Amaral <amaralp@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555099}
  • Loading branch information
zuojinglong authored and Commit Bot committed May 1, 2018
1 parent 8c68c6d commit e9c5bc1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ Jihoon Chung <jihoon@gmail.com>
Jihun Brent Kim <devgrapher@gmail.com>
Jin Yang <jin.a.yang@intel.com>
Jincheol Jo <jincheol.jo@navercorp.com>
Jinglong Zuo <zuojinglong@xiaomi.com>
Jingwei Liu <kingweiliu@gmail.com>
Jingyi Wei <wjywbs@gmail.com>
Jinho Bang <jinho.bang@samsung.com>
Expand Down
4 changes: 4 additions & 0 deletions content/renderer/render_frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4587,6 +4587,10 @@ void RenderFrameImpl::ShowContextMenu(const blink::WebContextMenuData& data) {
}

void RenderFrameImpl::ShowDeferredContextMenu(const ContextMenuParams& params) {
// TODO (amaralp): Remove this once selection menu race conditions are fixed.
if (selection_text_.empty() && !params.selection_text.empty())
return;

Send(new FrameHostMsg_ContextMenu(routing_id_, params));
}

Expand Down
50 changes: 50 additions & 0 deletions content/renderer/render_view_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
#include "third_party/blink/public/platform/web_gesture_device.h"
#include "third_party/blink/public/platform/web_gesture_event.h"
#include "third_party/blink/public/platform/web_input_event.h"
#include <android/keycodes.h>
#endif

#if defined(OS_WIN)
Expand Down Expand Up @@ -1552,6 +1553,55 @@ TEST_F(RenderViewImplTest, AndroidContextMenuSelectionOrdering) {
ExecuteJavaScriptAndReturnIntValue(check_did_select, &did_select));
EXPECT_EQ(1, did_select);
}

TEST_F(RenderViewImplTest, AndroidContextMenuSelectionCleared) {
// Load an HTML page consisting of an input field.
LoadHTML("<html>"
"<head>"
"</head>"
"<body>"
"<input id=\"test1\" value=\"abcdefghijklmnopqrstuvwxyz\"></input>"
"</body>"
"</html>");

WebGestureEvent gesture_event(WebInputEvent::kGestureTap,
WebInputEvent::kNoModifiers,
ui::EventTimeForNow());
gesture_event.SetPositionInWidget(gfx::PointF(20, 20));

SendWebGestureEvent(gesture_event);

frame()->GetWebFrame()->ExecuteCommand("SelectAll");

blink::WebKeyboardEvent event(blink::WebKeyboardEvent::kRawKeyDown,
blink::WebInputEvent::kNoModifiers,
ui::EventTimeForNow());
event.windows_key_code = ui::VKEY_BACK;
event.native_key_code = AKEYCODE_DEL;
SendWebKeyboardEvent(event);

scoped_refptr<content::MessageLoopRunner> message_loop_runner =
new content::MessageLoopRunner;
blink::scheduler::GetSingleThreadTaskRunnerForTesting()->PostTask(
FROM_HERE, message_loop_runner->QuitClosure());

EXPECT_FALSE(render_thread_->sink().GetUniqueMessageMatching(
FrameHostMsg_ContextMenu::ID));

message_loop_runner->Run();

EXPECT_FALSE(render_thread_->sink().GetUniqueMessageMatching(
FrameHostMsg_ContextMenu::ID));

// Check whether text selection is cleared.
blink::WebInputMethodController* controller =
frame()->GetWebFrame()->GetInputMethodController();
blink::WebTextInputInfo info = controller->TextInputInfo();
EXPECT_EQ(0, info.selection_start);
EXPECT_EQ(0, info.selection_end);
}


#endif

TEST_F(RenderViewImplTest, TestBackForward) {
Expand Down

0 comments on commit e9c5bc1

Please sign in to comment.