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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_gtk.h

Issue 151006: Make Linux restore Omnibox contents on tab switch. (Closed)
Patch Set: free string returned by gtk Created 11 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_ 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_ 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_
7 7
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 13 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
14 #include "chrome/browser/toolbar_model.h" 14 #include "chrome/browser/toolbar_model.h"
15 #include "chrome/common/owned_widget_gtk.h" 15 #include "chrome/common/owned_widget_gtk.h"
16 #include "chrome/common/page_transition_types.h" 16 #include "chrome/common/page_transition_types.h"
17 #include "webkit/glue/window_open_disposition.h" 17 #include "webkit/glue/window_open_disposition.h"
18 18
19 class AutocompleteEditController; 19 class AutocompleteEditController;
20 class AutocompleteEditModel; 20 class AutocompleteEditModel;
21 class AutocompletePopupPositioner; 21 class AutocompletePopupPositioner;
22 class AutocompletePopupViewGtk; 22 class AutocompletePopupViewGtk;
23 class CommandUpdater; 23 class CommandUpdater;
24 class Profile; 24 class Profile;
25 class TabContents; 25 class TabContents;
26 26
27 class AutocompleteEditViewGtk : public AutocompleteEditView { 27 class AutocompleteEditViewGtk : public AutocompleteEditView {
28 public: 28 public:
29 // Modeled like the Windows CHARRANGE. Represent a pair of cursor position
30 // offsets. Since GtkTextIters are invalid after the buffer is changed, we
31 // work in character offsets (not bytes).
32 struct CharRange {
33 CharRange() : cp_min(0), cp_max(0) { }
34 CharRange(int n, int x) : cp_min(n), cp_max(x) { }
35
36 // Work in integers to match the gint GTK APIs.
37 int cp_min; // For a selection: Represents the start.
38 int cp_max; // For a selection: Represents the end (insert position).
39 };
40
29 AutocompleteEditViewGtk(AutocompleteEditController* controller, 41 AutocompleteEditViewGtk(AutocompleteEditController* controller,
30 ToolbarModel* toolbar_model, 42 ToolbarModel* toolbar_model,
31 Profile* profile, 43 Profile* profile,
32 CommandUpdater* command_updater, 44 CommandUpdater* command_updater,
33 AutocompletePopupPositioner* popup_positioner); 45 AutocompletePopupPositioner* popup_positioner);
34 ~AutocompleteEditViewGtk(); 46 ~AutocompleteEditViewGtk();
35 47
36 // Initialize, create the underlying widgets, etc. 48 // Initialize, create the underlying widgets, etc.
37 void Init(); 49 void Init();
38 50
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 91
80 virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, 92 virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text,
81 bool save_original_selection); 93 bool save_original_selection);
82 virtual bool OnInlineAutocompleteTextMaybeChanged( 94 virtual bool OnInlineAutocompleteTextMaybeChanged(
83 const std::wstring& display_text, size_t user_text_length); 95 const std::wstring& display_text, size_t user_text_length);
84 virtual void OnRevertTemporaryText(); 96 virtual void OnRevertTemporaryText();
85 virtual void OnBeforePossibleChange(); 97 virtual void OnBeforePossibleChange();
86 virtual bool OnAfterPossibleChange(); 98 virtual bool OnAfterPossibleChange();
87 99
88 private: 100 private:
89 // Modeled like the Windows CHARRANGE. Represent a pair of cursor position
90 // offsets. Since GtkTextIters are invalid after the buffer is changed, we
91 // work in character offsets (not bytes).
92 struct CharRange {
93 CharRange() : cp_min(0), cp_max(0) { }
94 CharRange(int n, int x) : cp_min(n), cp_max(x) { }
95
96 // Work in integers to match the gint GTK APIs.
97 int cp_min; // For a selection: Represents the start.
98 int cp_max; // For a selection: Represents the end (insert position).
99 };
100
101 // TODO(deanm): Would be nice to insulate the thunkers better, etc. 101 // TODO(deanm): Would be nice to insulate the thunkers better, etc.
102 static void HandleBeginUserActionThunk(GtkTextBuffer* unused, gpointer self) { 102 static void HandleBeginUserActionThunk(GtkTextBuffer* unused, gpointer self) {
103 reinterpret_cast<AutocompleteEditViewGtk*>(self)->HandleBeginUserAction(); 103 reinterpret_cast<AutocompleteEditViewGtk*>(self)->HandleBeginUserAction();
104 } 104 }
105 void HandleBeginUserAction(); 105 void HandleBeginUserAction();
106 106
107 static void HandleEndUserActionThunk(GtkTextBuffer* unused, gpointer self) { 107 static void HandleEndUserActionThunk(GtkTextBuffer* unused, gpointer self) {
108 reinterpret_cast<AutocompleteEditViewGtk*>(self)->HandleEndUserAction(); 108 reinterpret_cast<AutocompleteEditViewGtk*>(self)->HandleEndUserAction();
109 } 109 }
110 void HandleEndUserAction(); 110 void HandleEndUserAction();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const gchar* text, 194 const gchar* text,
195 gpointer self) { 195 gpointer self) {
196 // If there is nothing to paste (|text| is NULL), do nothing. 196 // If there is nothing to paste (|text| is NULL), do nothing.
197 if (!text) 197 if (!text)
198 return; 198 return;
199 reinterpret_cast<AutocompleteEditViewGtk*>(self)-> 199 reinterpret_cast<AutocompleteEditViewGtk*>(self)->
200 HandlePasteAndGoReceivedText(UTF8ToWide(text)); 200 HandlePasteAndGoReceivedText(UTF8ToWide(text));
201 } 201 }
202 void HandlePasteAndGoReceivedText(const std::wstring& text); 202 void HandlePasteAndGoReceivedText(const std::wstring& text);
203 203
204 static void HandleMarkSetThunk(GtkTextBuffer* buffer,
205 GtkTextIter* location,
206 GtkTextMark* mark,
207 gpointer self) {
208 reinterpret_cast<AutocompleteEditViewGtk*>(self)->
209 HandleMarkSet(buffer, location, mark);
210 }
211 void HandleMarkSet(GtkTextBuffer* buffer,
212 GtkTextIter* location,
213 GtkTextMark* mark);
214
204 // Get the character indices of the current selection. This honors 215 // Get the character indices of the current selection. This honors
205 // direction, cp_max is the insertion point, and cp_min is the bound. 216 // direction, cp_max is the insertion point, and cp_min is the bound.
206 CharRange GetSelection(); 217 CharRange GetSelection();
207 218
208 // Translate from character positions to iterators for the current buffer. 219 // Translate from character positions to iterators for the current buffer.
209 void ItersFromCharRange(const CharRange& range, 220 void ItersFromCharRange(const CharRange& range,
210 GtkTextIter* iter_min, 221 GtkTextIter* iter_min,
211 GtkTextIter* iter_max); 222 GtkTextIter* iter_max);
212 223
213 // Return the number of characers in the current buffer. 224 // Return the number of characers in the current buffer.
214 int GetTextLength(); 225 int GetTextLength();
215 226
216 // Try to parse the current text as a URL and colorize the components. 227 // Try to parse the current text as a URL and colorize the components.
217 void EmphasizeURLComponents(); 228 void EmphasizeURLComponents();
218 229
219 // Internally invoked whenever the text changes in some way. 230 // Internally invoked whenever the text changes in some way.
220 void TextChanged(); 231 void TextChanged();
221 232
233 // Save 'selected_text' as the PRIMARY X selection.
234 void SavePrimarySelection(const std::string& selected_text);
235
222 // The widget we expose, used for vertically centering the real text edit, 236 // The widget we expose, used for vertically centering the real text edit,
223 // since the height will change based on the font / font size, etc. 237 // since the height will change based on the font / font size, etc.
224 OwnedWidgetGtk alignment_; 238 OwnedWidgetGtk alignment_;
225 239
226 // The actual text entry which will be owned by the alignment_. 240 // The actual text entry which will be owned by the alignment_.
227 GtkWidget* text_view_; 241 GtkWidget* text_view_;
228 242
229 GtkTextTagTable* tag_table_; 243 GtkTextTagTable* tag_table_;
230 GtkTextBuffer* text_buffer_; 244 GtkTextBuffer* text_buffer_;
231 GtkTextTag* base_tag_; 245 GtkTextTag* base_tag_;
232 GtkTextTag* secure_scheme_tag_; 246 GtkTextTag* secure_scheme_tag_;
233 GtkTextTag* insecure_scheme_tag_; 247 GtkTextTag* insecure_scheme_tag_;
234 GtkTextTag* black_text_tag_; 248 GtkTextTag* black_text_tag_;
235 249
236 // The primary selection clipboard for our text view widget. This is used
237 // for working around some clipboard manager (klipper / glipper) bugs by
238 // removing and adding back the clipboard around inline autocomplete.
239 GtkClipboard* primary_clipboard_;
240
241 scoped_ptr<AutocompleteEditModel> model_; 250 scoped_ptr<AutocompleteEditModel> model_;
242 scoped_ptr<AutocompletePopupViewGtk> popup_view_; 251 scoped_ptr<AutocompletePopupViewGtk> popup_view_;
243 AutocompleteEditController* controller_; 252 AutocompleteEditController* controller_;
244 ToolbarModel* toolbar_model_; 253 ToolbarModel* toolbar_model_;
245 254
246 // The object that handles additional command functionality exposed on the 255 // The object that handles additional command functionality exposed on the
247 // edit, such as invoking the keyword editor. 256 // edit, such as invoking the keyword editor.
248 CommandUpdater* command_updater_; 257 CommandUpdater* command_updater_;
249 258
250 // When true, the location bar view is read only and also is has a slightly 259 // When true, the location bar view is read only and also is has a slightly
251 // different presentation (font size / color). This is used for popups. 260 // different presentation (font size / color). This is used for popups.
252 // TODO(deanm). 261 // TODO(deanm).
253 bool popup_window_mode_; 262 bool popup_window_mode_;
254 263
255 ToolbarModel::SecurityLevel scheme_security_level_; 264 ToolbarModel::SecurityLevel scheme_security_level_;
256 265
257 // Tracking state before and after a possible change. 266 // Tracking state before and after a possible change.
258 std::wstring text_before_change_; 267 std::wstring text_before_change_;
259 CharRange sel_before_change_; 268 CharRange sel_before_change_;
260 269
270 // The most-recently-selected text from the entry. This is updated on-the-fly
271 // as the user selects text. It is used in cases where we need to make the
272 // PRIMARY selection persist even after the user has unhighlighted the text in
273 // the view (e.g. when they highlight some text and then click to unhighlight
274 // it, we pass this string to SavePrimarySelection()).
275 std::string selected_text_;
276
277 // Has the current value of 'selected_text_' been saved as the PRIMARY
278 // selection?
279 bool selection_saved_;
280
261 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewGtk); 281 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewGtk);
262 }; 282 };
263 283
264 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_ 284 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698