1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
// Copyright (c) 2009 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.
#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_MAC_H_
#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_MAC_H_
#import <Cocoa/Cocoa.h>
#include "base/basictypes.h"
#include "base/scoped_nsobject.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/toolbar_model.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/window_open_disposition.h"
class AutocompleteEditController;
@class AutocompleteEditHelper;
class AutocompleteEditModel;
class AutocompletePopupPositioner;
class AutocompletePopupViewMac;
@class AutocompleteTextField;
class Clipboard;
class CommandUpdater;
class Profile;
class TabContents;
class ToolbarModel;
// Implements AutocompleteEditView on an AutocompleteTextField.
class AutocompleteEditViewMac : public AutocompleteEditView {
public:
AutocompleteEditViewMac(AutocompleteEditController* controller,
AutocompletePopupPositioner* positioner,
ToolbarModel* toolbar_model,
Profile* profile,
CommandUpdater* command_updater,
AutocompleteTextField* field);
virtual ~AutocompleteEditViewMac();
// Implement the AutocompleteEditView interface.
// TODO(shess): See if this couldn't be simplified to:
// virtual AEM* model() const { ... }
virtual AutocompleteEditModel* model() { return model_.get(); }
virtual const AutocompleteEditModel* model() const { return model_.get(); }
virtual void SaveStateToTab(TabContents* tab);
virtual void Update(const TabContents* tab_for_state_restoring);
virtual void OpenURL(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
const GURL& alternate_nav_url,
size_t selected_line,
const std::wstring& keyword);
virtual std::wstring GetText() const;
virtual void SetUserText(const std::wstring& text) {
SetUserText(text, text, true);
}
virtual void SetUserText(const std::wstring& text,
const std::wstring& display_text,
bool update_popup);
virtual void SetWindowTextAndCaretPos(const std::wstring& text,
size_t caret_pos);
virtual void SetForcedQuery() { NOTIMPLEMENTED(); }
virtual bool IsSelectAll() {
NOTIMPLEMENTED();
return false;
}
virtual void SelectAll(bool reversed);
virtual void RevertAll();
virtual void UpdatePopup();
virtual void ClosePopup();
virtual void SetFocus();
virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text,
bool save_original_selection);
virtual bool OnInlineAutocompleteTextMaybeChanged(
const std::wstring& display_text, size_t user_text_length);
virtual void OnRevertTemporaryText();
virtual void OnBeforePossibleChange();
virtual bool OnAfterPossibleChange();
virtual gfx::NativeView GetNativeView() const;
// Helper functions for use from AutocompleteEditHelper Objective-C
// class.
// Returns true if |popup_view_| is open.
bool IsPopupOpen() const;
// Trivial wrappers forwarding to |model_| methods.
void OnControlKeyChanged(bool pressed);
void OnEscapeKeyPressed();
void OnUpOrDownKeyPressed(bool up, bool by_page);
// Called when editing begins in the field, and before the results
// of any editing are communicated to |model_|.
void OnWillBeginEditing();
// Called when editing ends in the field.
void OnDidEndEditing();
// Called when the window |field_| is in loses key to clean up
// visual state (such as closing the popup).
void OnDidResignKey();
// Called when the user attempts to paste into |field_|.
void OnPaste();
// Checks if a keyword search is possible and forwards to |model_|
// if so. Returns true if the tab should be eaten.
bool OnTabPressed();
// Called when the user hits backspace in |field_|. Checks whether
// keyword search is being terminated. Returns true if the
// backspace should be intercepted (not forwarded on to the standard
// machinery).
bool OnBackspacePressed();
// Forward to same method in |popup_view_| model. Used when
// Shift-Delete is pressed, to delete items from the popup.
void TryDeletingCurrentItem();
void AcceptInput(WindowOpenDisposition disposition, bool for_drop);
// Helper for LocationBarViewMac. Selects all in |field_|.
void FocusLocation();
// Helper to get appropriate contents from |clipboard|. Returns
// empty string if no appropriate data is found on |clipboard|.
static std::wstring GetClipboardText(Clipboard* clipboard);
private:
// Returns the field's currently selected range. Only valid if the
// field has focus.
NSRange GetSelectedRange() const;
// Returns true if |field_| is first-responder in the window. Used
// in various DCHECKS to make sure code is running in appropriate
// situations.
bool IsFirstResponder() const;
// If |model_| believes it has focus, grab focus if needed and set
// the selection to |range|. Otherwise does nothing.
void SetSelectedRange(const NSRange range);
// Update the field with |display_text| and highlight the host and
// scheme (if it's an URL or URL-fragment).
void SetText(const std::wstring& display_text);
// Update the field with |display_text| and set the selection.
void SetTextAndSelectedRange(const std::wstring& display_text,
const NSRange range);
// Pass the current content of |field_| to SetText(), maintaining
// any selection. Named to be consistent with GTK and Windows,
// though here we cannot really do the in-place operation they do.
void EmphasizeURLComponents();
scoped_ptr<AutocompleteEditModel> model_;
scoped_ptr<AutocompletePopupViewMac> popup_view_;
AutocompleteEditController* controller_;
ToolbarModel* toolbar_model_;
// The object that handles additional command functionality exposed on the
// edit, such as invoking the keyword editor.
CommandUpdater* command_updater_;
AutocompleteTextField* field_; // owned by tab controller
// Objective-C object to bridge field_ delegate calls to C++.
scoped_nsobject<AutocompleteEditHelper> edit_helper_;
// Selection at the point where the user started using the
// arrows to move around in the popup.
NSRange saved_temporary_selection_;
// Tracking state before and after a possible change for reporting
// to model_.
NSRange selection_before_change_;
std::wstring text_before_change_;
DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewMac);
};
#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_MAC_H_
|