Commit 2a741a1f authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Propagate the Views Find Bar Text Changes to the Pasteboard

Adds support to get the views find bar text to the global pasteboard.
Also fixes a Cocoa bug introduced in the previous pasteboard change
where the selection is always reset to the beginning at every keystroke.

BUG=826478,827189,842131

Change-Id: If1a639f1997e3fea7fee2c66959e7dcdb2fd3bc7
Reviewed-on: https://chromium-review.googlesource.com/1055195
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557902}
parent 8f26e2ab
......@@ -138,7 +138,12 @@ void FindBarController::ChangeWebContents(WebContents* contents) {
}
void FindBarController::SetText(base::string16 text) {
find_bar_->SetFindTextAndSelectedRange(text, gfx::Range());
find_bar_->SetFindTextAndSelectedRange(text, find_bar_->GetSelectedRange());
}
void FindBarController::OnUserChangedFindText(base::string16 text) {
if (find_bar_platform_helper_)
find_bar_platform_helper_->OnUserChangedFindText(text);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -74,6 +74,9 @@ class FindBarController : public content::NotificationObserver {
void SetText(base::string16 text);
// Called when the find text is updated in response to a user action.
void OnUserChangedFindText(base::string16 text);
Browser* browser() const { return browser_; }
FindBar* find_bar() const { return find_bar_.get(); }
......
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/macros.h"
#include "base/strings/string16.h"
class FindBarController;
......@@ -19,6 +20,9 @@ class FindBarPlatformHelper {
virtual ~FindBarPlatformHelper();
// Called when the user changes the find text to |text|.
virtual void OnUserChangedFindText(base::string16 text) = 0;
protected:
explicit FindBarPlatformHelper(FindBarController* find_bar_controller);
......
......@@ -5,6 +5,7 @@
#import <Foundation/Foundation.h>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
......@@ -36,6 +37,11 @@ class FindBarPlatformHelperMac : public FindBarPlatformHelper {
removeObserver:find_pasteboard_notification_observer_];
}
void OnUserChangedFindText(base::string16 text) override {
[[FindPasteboard sharedInstance]
setFindText:base::SysUTF16ToNSString(text)];
}
private:
void UpdateFindBarControllerFromPasteboard() {
content::WebContents* active_web_contents =
......
// Copyright 2018 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.
#import <Cocoa/Cocoa.h>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/views/scoped_macviews_browser_mode.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "ui/base/cocoa/find_pasteboard.h"
class FindBarPlatformHelperMacInteractiveUITest
: public InProcessBrowserTest,
public testing::WithParamInterface<bool> {
public:
FindBarPlatformHelperMacInteractiveUITest()
: scoped_macviews_browser_mode_(GetParam()) {}
~FindBarPlatformHelperMacInteractiveUITest() override = default;
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
old_find_text_ = [[FindPasteboard sharedInstance] findText];
}
void TearDownOnMainThread() override {
[[FindPasteboard sharedInstance] setFindText:old_find_text_];
InProcessBrowserTest::TearDownOnMainThread();
}
static std::string ParamInfoToString(
::testing::TestParamInfo<bool> param_info) {
return param_info.param ? "Views" : "Cocoa";
}
private:
test::ScopedMacViewsBrowserMode scoped_macviews_browser_mode_;
NSString* old_find_text_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FindBarPlatformHelperMacInteractiveUITest);
};
// Tests that the pasteboard is updated when the find bar is changed.
IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
PasteboardUpdatedFromFindBar) {
FindBarController* find_bar_controller = browser()->GetFindBarController();
ASSERT_NE(nullptr, find_bar_controller);
base::string16 empty_string(base::ASCIIToUTF16(""));
find_bar_controller->SetText(empty_string);
chrome::Find(browser());
EXPECT_TRUE(
ui_test_utils::IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_A, false,
false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_S, false,
false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_D, false,
false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_F, false,
false, false, false));
base::string16 find_bar_string =
find_bar_controller->find_bar()->GetFindText();
ASSERT_EQ(base::ASCIIToUTF16("asdf"), find_bar_string);
EXPECT_EQ(find_bar_string, base::SysNSStringToUTF16(
[[FindPasteboard sharedInstance] findText]));
}
INSTANTIATE_TEST_CASE_P(
,
FindBarPlatformHelperMacInteractiveUITest,
::testing::Bool(),
FindBarPlatformHelperMacInteractiveUITest::ParamInfoToString);
......@@ -412,6 +412,8 @@ void FindBarView::Find(const base::string16& search_text) {
last_searched_text_ = search_text;
controller->OnUserChangedFindText(search_text);
// When the user changes something in the text box we check the contents and
// if the textbox contains something we set it as the new search string and
// initiate search (even though old searches might be in progress).
......
......@@ -4965,6 +4965,7 @@ if (!is_android) {
if (is_mac) {
sources += [
"../browser/ui/find_bar/find_bar_platform_helper_mac_interactive_uitest.mm",
"base/interactive_test_utils_cocoa.h",
"base/interactive_test_utils_cocoa.mm",
]
......
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