summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-22 23:28:28 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-22 23:28:28 +0000
commit95776be964aad978fa4686beb90065c6b8654f6b (patch)
treef8226feb6fe26d078aabde9767f6561cc4fc5dc4 /chrome/browser/cocoa
parent30e25a3e5b5160a3857b062db812b509a5a32dad (diff)
downloadchromium_src-95776be964aad978fa4686beb90065c6b8654f6b.zip
chromium_src-95776be964aad978fa4686beb90065c6b8654f6b.tar.gz
chromium_src-95776be964aad978fa4686beb90065c6b8654f6b.tar.bz2
[Mac] Implement suggested results in the omnibox.
BUG=56385 TEST=Suggest text should appear when instant is on. Review URL: http://codereview.chromium.org/4643008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/location_bar/autocomplete_text_field.h3
-rw-r--r--chrome/browser/cocoa/location_bar/autocomplete_text_field.mm8
-rw-r--r--chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.mm13
-rw-r--r--chrome/browser/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm3
-rw-r--r--chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest.mm14
-rw-r--r--chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest_helper.h1
-rw-r--r--chrome/browser/cocoa/location_bar/location_bar_view_mac.mm9
7 files changed, 49 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field.h b/chrome/browser/cocoa/location_bar/autocomplete_text_field.h
index 0c8f060..9123578 100644
--- a/chrome/browser/cocoa/location_bar/autocomplete_text_field.h
+++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field.h
@@ -33,6 +33,9 @@
// AutocompleteEditViewMac rather than traversing the delegate chain.
class AutocompleteTextFieldObserver {
public:
+ // Called before changing the selected range of the field.
+ virtual NSRange SelectionRangeForProposedRange(NSRange proposed_range) = 0;
+
// Called when the control-key state changes while the field is
// first responder.
virtual void OnControlKeyChanged(bool pressed) = 0;
diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field.mm b/chrome/browser/cocoa/location_bar/autocomplete_text_field.mm
index 4f18f68..f340b70 100644
--- a/chrome/browser/cocoa/location_bar/autocomplete_text_field.mm
+++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field.mm
@@ -207,6 +207,14 @@
[undoManager_ removeAllActions];
}
+- (NSRange)textView:(NSTextView *)aTextView
+ willChangeSelectionFromCharacterRange:(NSRange)oldRange
+ toCharacterRange:(NSRange)newRange {
+ if (observer_)
+ return observer_->SelectionRangeForProposedRange(newRange);
+ return newRange;
+}
+
- (void)addToolTip:(NSString*)tooltip forRect:(NSRect)aRect {
[currentToolTips_ addObject:tooltip];
[self addToolTipRect:aRect owner:tooltip userData:nil];
diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.mm b/chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.mm
index aa5d391..9275945 100644
--- a/chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.mm
+++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.mm
@@ -271,6 +271,19 @@
[self didChangeText];
}
+- (NSRange)selectionRangeForProposedRange:(NSRange)proposedSelRange
+ granularity:(NSSelectionGranularity)granularity {
+ AutocompleteTextFieldObserver* observer = [self observer];
+ NSRange modifiedRange = [super selectionRangeForProposedRange:proposedSelRange
+ granularity:granularity];
+ if (observer)
+ return observer->SelectionRangeForProposedRange(modifiedRange);
+ return modifiedRange;
+}
+
+
+
+
- (void)setSelectedRange:(NSRange)charRange
affinity:(NSSelectionAffinity)affinity
stillSelecting:(BOOL)flag {
diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm b/chrome/browser/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm
index 21ad21a..04342ce 100644
--- a/chrome/browser/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm
+++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field_editor_unittest.mm
@@ -19,6 +19,7 @@
#import "third_party/ocmock/OCMock/OCMock.h"
using ::testing::Return;
+using ::testing::ReturnArg;
using ::testing::StrictMock;
using ::testing::A;
@@ -206,6 +207,8 @@ TEST_F(AutocompleteTextFieldEditorObserverTest, Cut) {
NSString* test_string = @"astring";
EXPECT_CALL(field_observer_, OnDidBeginEditing());
EXPECT_CALL(field_observer_, OnDidChange());
+ EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(A<NSRange>()))
+ .WillRepeatedly(ReturnArg<0>());
[editor_ setString:test_string];
[editor_ selectAll:nil];
diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest.mm
index f39400e..17fdfc0 100644
--- a/chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest.mm
@@ -19,8 +19,10 @@
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
+using ::testing::A;
using ::testing::InSequence;
using ::testing::Return;
+using ::testing::ReturnArg;
using ::testing::StrictMock;
using ::testing::_;
@@ -226,6 +228,10 @@ TEST_F(AutocompleteTextFieldObserverTest, FlagsChanged) {
// field catches -flagsChanged: because it's on the responder chain,
// the field editor doesn't implement it.
TEST_F(AutocompleteTextFieldObserverTest, FieldEditorFlagsChanged) {
+ // Many of these methods try to change the selection.
+ EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(A<NSRange>()))
+ .WillRepeatedly(ReturnArg<0>());
+
InSequence dummy; // Call mock in exactly the order specified.
EXPECT_CALL(field_observer_, OnSetFocus(false));
[test_window() makePretendKeyWindowAndSetFirstResponder:field_];
@@ -312,6 +318,10 @@ TEST_F(AutocompleteTextFieldTest, ResetFieldEditorWithDecoration) {
// Test that resetting the field editor bounds does not cause untoward
// messages to the field's observer.
TEST_F(AutocompleteTextFieldObserverTest, ResetFieldEditorContinuesEditing) {
+ // Many of these methods try to change the selection.
+ EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(A<NSRange>()))
+ .WillRepeatedly(ReturnArg<0>());
+
EXPECT_CALL(field_observer_, OnSetFocus(false));
// Becoming first responder doesn't begin editing.
[test_window() makePretendKeyWindowAndSetFirstResponder:field_];
@@ -727,6 +737,10 @@ TEST_F(AutocompleteTextFieldTest, EditorGetsCorrectUndoManager) {
}
TEST_F(AutocompleteTextFieldObserverTest, SendsEditingMessages) {
+ // Many of these methods try to change the selection.
+ EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(A<NSRange>()))
+ .WillRepeatedly(ReturnArg<0>());
+
EXPECT_CALL(field_observer_, OnSetFocus(false));
// Becoming first responder doesn't begin editing.
[test_window() makePretendKeyWindowAndSetFirstResponder:field_];
diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest_helper.h b/chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest_helper.h
index eb78594..6db113a 100644
--- a/chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest_helper.h
+++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest_helper.h
@@ -35,6 +35,7 @@ namespace {
class MockAutocompleteTextFieldObserver : public AutocompleteTextFieldObserver {
public:
+ MOCK_METHOD1(SelectionRangeForProposedRange, NSRange(NSRange range));
MOCK_METHOD1(OnControlKeyChanged, void(bool pressed));
MOCK_METHOD0(CanCopy, bool());
MOCK_METHOD1(CopyToPasteboard, void(NSPasteboard* pboard));
diff --git a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
index b19f01c..c897465 100644
--- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
@@ -141,7 +141,7 @@ std::wstring LocationBarViewMac::GetInputString() const {
}
void LocationBarViewMac::SetSuggestedText(const string16& text) {
- // TODO(rohitrao): implement me. http://crbug.com/56385
+ edit_view_->SetSuggestText(text);
}
WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const {
@@ -222,9 +222,12 @@ void LocationBarViewMac::OnAutocompleteWillClosePopup() {
InstantController* controller = browser_->instant();
if (controller && !controller->commit_on_mouse_up())
controller->DestroyPreviewContents();
+ SetSuggestedText(string16());
}
void LocationBarViewMac::OnAutocompleteLosingFocus(gfx::NativeView unused) {
+ SetSuggestedText(string16());
+
InstantController* instant = browser_->instant();
if (!instant)
return;
@@ -248,7 +251,7 @@ void LocationBarViewMac::OnAutocompleteWillAccept() {
}
bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) {
- return false;
+ return edit_view_->CommitSuggestText();
}
void LocationBarViewMac::OnSetSuggestedSearchText(
@@ -325,6 +328,8 @@ void LocationBarViewMac::OnChanged() {
instant->DestroyPreviewContents();
}
}
+
+ SetSuggestedText(suggested_text);
}
void LocationBarViewMac::OnSelectionBoundsChanged() {