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

Unified Diff: content/public/test/text_input_test_utils_mac.mm

Issue 2382003002: Fix dictionary look-up for highlighted text in Mac. (Closed)
Patch Set: Rebased Created 4 years, 2 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
Index: content/public/test/text_input_test_utils_mac.mm
diff --git a/content/public/test/text_input_test_utils_mac.mm b/content/public/test/text_input_test_utils_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..29de863f77e08963d08f9e402886c6b403d30edc
--- /dev/null
+++ b/content/public/test/text_input_test_utils_mac.mm
@@ -0,0 +1,78 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/test/text_input_test_utils.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/memory/ref_counted.h"
+#include "base/strings/sys_string_conversions.h"
+#include "content/browser/renderer_host/render_widget_host_view_mac.h"
+#include "content/browser/site_instance_impl.h"
+#include "content/common/mac/attributed_string_coder.h"
+#include "content/common/text_input_client_messages.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/test/test_utils.h"
+#include "ipc/ipc_message_macros.h"
+
+namespace content {
+
+TestTextInputClientMessageFilter::TestTextInputClientMessageFilter(
+ RenderProcessHost* host)
+ : BrowserMessageFilter(TextInputClientMsgStart),
+ host_(host),
+ received_string_from_range_(false) {
+ host->AddFilter(this);
+}
+
+TestTextInputClientMessageFilter::~TestTextInputClientMessageFilter() {}
+
+void TestTextInputClientMessageFilter::WaitForStringFromRange() {
+ if (received_string_from_range_)
+ return;
+ message_loop_runner_ = new MessageLoopRunner();
+ message_loop_runner_->Run();
+}
+
+bool TestTextInputClientMessageFilter::OnMessageReceived(
+ const IPC::Message& message) {
+ if (message.type() == TextInputClientReplyMsg_GotStringForRange::ID) {
+ received_string_from_range_ = true;
+
+ // Now decode the string to get the word.
+ TextInputClientReplyMsg_GotStringForRange::Param params;
+ TextInputClientReplyMsg_GotStringForRange::Read(&message, &params);
+ const mac::AttributedStringCoder::EncodedString& encoded_string =
+ std::get<0>(params);
+ NSAttributedString* decoded =
+ mac::AttributedStringCoder::Decode(&encoded_string);
+ string_from_range_ = base::SysNSStringToUTF8([decoded string]);
+
+ // Stop the message loop if it is running.
+ if (message_loop_runner_) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ message_loop_runner_->QuitClosure());
+ }
+ }
+
+ // unhandled - leave it for the actual TextInputClientMessageFilter to handle.
+ return false;
+}
+
+void AskForLookUpDictionaryForRange(RenderWidgetHostView* tab_view,
+ const gfx::Range& range) {
+ RenderWidgetHostViewCocoa* cocoa_view =
+ static_cast<RenderWidgetHostViewMac*>(tab_view)->cocoa_view();
+
+ // Explicitly ask for the dictionary for the given range.
+ [cocoa_view showLookUpDictionaryOverlayFromRange:range.ToNSRange()
+ targetView:cocoa_view];
+}
+
+size_t GetOpenNSWindowsCount() {
+ return [[NSApp windows] count];
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698