OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ | 5 #ifndef CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ |
6 #define CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ | 6 #define CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 16 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
17 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 17 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
20 #include "ui/base/animation/animation_delegate.h" | 20 #include "ui/base/animation/animation_delegate.h" |
21 #include "ui/base/gtk/gtk_signal.h" | 21 #include "ui/base/gtk/gtk_signal.h" |
22 #include "ui/base/gtk/gtk_signal_registrar.h" | 22 #include "ui/base/gtk/gtk_signal_registrar.h" |
23 #include "ui/base/gtk/owned_widget_gtk.h" | 23 #include "ui/base/gtk/owned_widget_gtk.h" |
24 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
25 #include "webkit/glue/window_open_disposition.h" | 25 #include "webkit/glue/window_open_disposition.h" |
26 | 26 |
27 class Browser; | 27 class Browser; |
28 class OmniboxEditController; | |
29 class OmniboxEditModel; | |
30 class OmniboxPopupView; | 28 class OmniboxPopupView; |
31 class Profile; | 29 class Profile; |
32 | 30 |
33 namespace gfx { | 31 namespace gfx { |
34 class Font; | 32 class Font; |
35 } | 33 } |
36 | 34 |
37 namespace ui { | 35 namespace ui { |
38 class MultiAnimation; | 36 class MultiAnimation; |
39 } | 37 } |
(...skipping 29 matching lines...) Expand all Loading... | |
69 virtual ~OmniboxViewGtk(); | 67 virtual ~OmniboxViewGtk(); |
70 | 68 |
71 // Initialize, create the underlying widgets, etc. | 69 // Initialize, create the underlying widgets, etc. |
72 void Init(); | 70 void Init(); |
73 // Returns the width in pixels needed to display the text from one character | 71 // Returns the width in pixels needed to display the text from one character |
74 // before the caret to the end of the string. See comments in | 72 // before the caret to the end of the string. See comments in |
75 // LocationBarView::Layout as to why this uses -1. | 73 // LocationBarView::Layout as to why this uses -1. |
76 int WidthOfTextAfterCursor(); | 74 int WidthOfTextAfterCursor(); |
77 | 75 |
78 // OmniboxView: | 76 // OmniboxView: |
79 virtual OmniboxEditModel* model() OVERRIDE; | |
80 virtual const OmniboxEditModel* model() const OVERRIDE; | |
81 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; | 77 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; |
82 virtual void Update( | 78 virtual void Update( |
83 const content::WebContents* tab_for_state_restoring) OVERRIDE; | 79 const content::WebContents* tab_for_state_restoring) OVERRIDE; |
84 virtual void OpenMatch(const AutocompleteMatch& match, | |
85 WindowOpenDisposition disposition, | |
86 const GURL& alternate_nav_url, | |
87 size_t index) OVERRIDE; | |
88 virtual string16 GetText() const OVERRIDE; | 80 virtual string16 GetText() const OVERRIDE; |
89 virtual bool IsEditingOrEmpty() const OVERRIDE; | |
90 virtual int GetIcon() const OVERRIDE; | |
91 virtual void SetUserText(const string16& text) OVERRIDE; | |
92 virtual void SetUserText(const string16& text, | |
93 const string16& display_text, | |
94 bool update_popup) OVERRIDE; | |
95 virtual void SetWindowTextAndCaretPos(const string16& text, | 81 virtual void SetWindowTextAndCaretPos(const string16& text, |
96 size_t caret_pos, | 82 size_t caret_pos, |
97 bool update_popup, | 83 bool update_popup, |
98 bool notify_text_changed) OVERRIDE; | 84 bool notify_text_changed) OVERRIDE; |
99 virtual void SetForcedQuery() OVERRIDE; | 85 virtual void SetForcedQuery() OVERRIDE; |
100 virtual bool IsSelectAll() const OVERRIDE; | 86 virtual bool IsSelectAll() const OVERRIDE; |
101 virtual bool DeleteAtEndPressed() OVERRIDE; | 87 virtual bool DeleteAtEndPressed() OVERRIDE; |
102 virtual void GetSelectionBounds(string16::size_type* start, | 88 virtual void GetSelectionBounds(string16::size_type* start, |
103 string16::size_type* end) const OVERRIDE; | 89 string16::size_type* end) const OVERRIDE; |
104 virtual void SelectAll(bool reversed) OVERRIDE; | 90 virtual void SelectAll(bool reversed) OVERRIDE; |
105 virtual void RevertAll() OVERRIDE; | |
106 virtual void UpdatePopup() OVERRIDE; | 91 virtual void UpdatePopup() OVERRIDE; |
107 virtual void ClosePopup() OVERRIDE; | |
108 virtual void SetFocus() OVERRIDE; | 92 virtual void SetFocus() OVERRIDE; |
109 virtual void OnTemporaryTextMaybeChanged( | 93 virtual void OnTemporaryTextMaybeChanged( |
110 const string16& display_text, | 94 const string16& display_text, |
111 bool save_original_selection) OVERRIDE; | 95 bool save_original_selection) OVERRIDE; |
112 virtual bool OnInlineAutocompleteTextMaybeChanged( | 96 virtual bool OnInlineAutocompleteTextMaybeChanged( |
113 const string16& display_text, size_t user_text_length) OVERRIDE; | 97 const string16& display_text, size_t user_text_length) OVERRIDE; |
114 virtual void OnRevertTemporaryText() OVERRIDE; | 98 virtual void OnRevertTemporaryText() OVERRIDE; |
115 virtual void OnBeforePossibleChange() OVERRIDE; | 99 virtual void OnBeforePossibleChange() OVERRIDE; |
116 virtual bool OnAfterPossibleChange() OVERRIDE; | 100 virtual bool OnAfterPossibleChange() OVERRIDE; |
117 virtual gfx::NativeView GetNativeView() const OVERRIDE; | 101 virtual gfx::NativeView GetNativeView() const OVERRIDE; |
118 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; | 102 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; |
119 virtual CommandUpdater* GetCommandUpdater() OVERRIDE; | |
120 virtual void SetInstantSuggestion(const string16& suggestion, | 103 virtual void SetInstantSuggestion(const string16& suggestion, |
121 bool animate_to_complete) OVERRIDE; | 104 bool animate_to_complete) OVERRIDE; |
122 virtual string16 GetInstantSuggestion() const OVERRIDE; | 105 virtual string16 GetInstantSuggestion() const OVERRIDE; |
123 virtual int TextWidth() const OVERRIDE; | 106 virtual int TextWidth() const OVERRIDE; |
124 virtual bool IsImeComposing() const OVERRIDE; | 107 virtual bool IsImeComposing() const OVERRIDE; |
125 | 108 |
126 // Overridden from content::NotificationObserver: | 109 // Overridden from content::NotificationObserver: |
127 virtual void Observe(int type, | 110 virtual void Observe(int type, |
128 const content::NotificationSource& source, | 111 const content::NotificationSource& source, |
129 const content::NotificationDetails& details) OVERRIDE; | 112 const content::NotificationDetails& details) OVERRIDE; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 static void ClipboardGetSelectionThunk(GtkClipboard* clipboard, | 210 static void ClipboardGetSelectionThunk(GtkClipboard* clipboard, |
228 GtkSelectionData* selection_data, | 211 GtkSelectionData* selection_data, |
229 guint info, | 212 guint info, |
230 gpointer object); | 213 gpointer object); |
231 void ClipboardGetSelection(GtkClipboard* clipboard, | 214 void ClipboardGetSelection(GtkClipboard* clipboard, |
232 GtkSelectionData* selection_data, | 215 GtkSelectionData* selection_data, |
233 guint info); | 216 guint info); |
234 | 217 |
235 void HandleCopyOrCutClipboard(bool copy); | 218 void HandleCopyOrCutClipboard(bool copy); |
236 | 219 |
220 // OmniboxView overrides. | |
Peter Kasting
2012/07/26 23:03:24
Nit: Still seems kind of randomly located. Maybe
dominich
2012/07/27 20:33:54
my thinking was:
below callbacks.
below static me
Peter Kasting
2012/07/28 00:23:06
Yeah, I'd probably put it above the static method,
| |
221 virtual int GetOmniboxTextLength() const OVERRIDE; | |
222 virtual void EmphasizeURLComponents() OVERRIDE; | |
223 | |
237 // Common implementation for performing a drop on the edit view. | 224 // Common implementation for performing a drop on the edit view. |
238 bool OnPerformDropImpl(const string16& text); | 225 bool OnPerformDropImpl(const string16& text); |
239 | 226 |
240 // Returns the font used in |text_view_|. | 227 // Returns the font used in |text_view_|. |
241 gfx::Font GetFont(); | 228 gfx::Font GetFont(); |
242 | 229 |
243 // Take control of the PRIMARY selection clipboard with |text|. Use | 230 // Take control of the PRIMARY selection clipboard with |text|. Use |
244 // |text_buffer_| as the owner, so that this doesn't remove the selection on | 231 // |text_buffer_| as the owner, so that this doesn't remove the selection on |
245 // it. This makes use of the above callbacks. | 232 // it. This makes use of the above callbacks. |
246 void OwnPrimarySelection(const std::string& text); | 233 void OwnPrimarySelection(const std::string& text); |
(...skipping 19 matching lines...) Expand all Loading... | |
266 | 253 |
267 // Get the character indices of the current selection. This honors | 254 // Get the character indices of the current selection. This honors |
268 // direction, cp_max is the insertion point, and cp_min is the bound. | 255 // direction, cp_max is the insertion point, and cp_min is the bound. |
269 CharRange GetSelection() const; | 256 CharRange GetSelection() const; |
270 | 257 |
271 // Translate from character positions to iterators for the current buffer. | 258 // Translate from character positions to iterators for the current buffer. |
272 void ItersFromCharRange(const CharRange& range, | 259 void ItersFromCharRange(const CharRange& range, |
273 GtkTextIter* iter_min, | 260 GtkTextIter* iter_min, |
274 GtkTextIter* iter_max); | 261 GtkTextIter* iter_max); |
275 | 262 |
276 // Return the number of characters in the current buffer. | |
277 int GetTextLength() const; | |
278 | |
279 // Places the caret at the given position. This clears any selection. | |
280 void PlaceCaretAt(int pos); | |
281 | |
282 // Returns true if the caret is at the end of the content. | 263 // Returns true if the caret is at the end of the content. |
283 bool IsCaretAtEnd() const; | 264 bool IsCaretAtEnd() const; |
284 | 265 |
285 // Try to parse the current text as a URL and colorize the components. | |
286 void EmphasizeURLComponents(); | |
287 | |
288 // Internally invoked whenever the text changes in some way. | |
289 void TextChanged(); | |
290 | |
291 // Save |selected_text| as the PRIMARY X selection. Unlike | 266 // Save |selected_text| as the PRIMARY X selection. Unlike |
292 // OwnPrimarySelection(), this won't set an owner or use callbacks. | 267 // OwnPrimarySelection(), this won't set an owner or use callbacks. |
293 void SavePrimarySelection(const std::string& selected_text); | 268 void SavePrimarySelection(const std::string& selected_text); |
294 | 269 |
295 // Update the field with |text| and set the selection. | 270 // Update the field with |text| and set the selection. |
296 void SetTextAndSelectedRange(const string16& text, | 271 void SetTextAndSelectedRange(const string16& text, |
297 const CharRange& range); | 272 const CharRange& range); |
298 | 273 |
299 // Set the selection to |range|. | 274 // Set the selection to |range|. |
300 void SetSelectedRange(const CharRange& range); | 275 void SetSelectedRange(const CharRange& range); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 GtkWidget* instant_view_; | 332 GtkWidget* instant_view_; |
358 // Animation from instant suggest (faded text) to autocomplete (selected | 333 // Animation from instant suggest (faded text) to autocomplete (selected |
359 // text). | 334 // text). |
360 scoped_ptr<ui::MultiAnimation> instant_animation_; | 335 scoped_ptr<ui::MultiAnimation> instant_animation_; |
361 | 336 |
362 // A mark to split the content and the instant anchor. Wherever the end | 337 // A mark to split the content and the instant anchor. Wherever the end |
363 // iterator of the text buffer is required, the iterator to this mark should | 338 // iterator of the text buffer is required, the iterator to this mark should |
364 // be used. | 339 // be used. |
365 GtkTextMark* instant_mark_; | 340 GtkTextMark* instant_mark_; |
366 | 341 |
367 scoped_ptr<OmniboxEditModel> model_; | |
368 scoped_ptr<OmniboxPopupView> popup_view_; | 342 scoped_ptr<OmniboxPopupView> popup_view_; |
369 OmniboxEditController* controller_; | |
370 ToolbarModel* toolbar_model_; | |
371 | |
372 // The object that handles additional command functionality exposed on the | |
373 // edit, such as invoking the keyword editor. | |
374 CommandUpdater* command_updater_; | |
375 | 343 |
376 // When true, the location bar view is read only and also is has a slightly | 344 // When true, the location bar view is read only and also is has a slightly |
377 // different presentation (smaller font size). This is used for popups. | 345 // different presentation (smaller font size). This is used for popups. |
378 bool popup_window_mode_; | 346 bool popup_window_mode_; |
379 | 347 |
380 ToolbarModel::SecurityLevel security_level_; | 348 ToolbarModel::SecurityLevel security_level_; |
381 | 349 |
382 // Selection at the point where the user started using the | 350 // Selection at the point where the user started using the |
383 // arrows to move around in the popup. | 351 // arrows to move around in the popup. |
384 CharRange saved_temporary_selection_; | 352 CharRange saved_temporary_selection_; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 // The view that is going to be focused next. Only valid while handling | 463 // The view that is going to be focused next. Only valid while handling |
496 // "focus-out" events. | 464 // "focus-out" events. |
497 GtkWidget* going_to_focus_; | 465 GtkWidget* going_to_focus_; |
498 | 466 |
499 ui::GtkSignalRegistrar signals_; | 467 ui::GtkSignalRegistrar signals_; |
500 | 468 |
501 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtk); | 469 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtk); |
502 }; | 470 }; |
503 | 471 |
504 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ | 472 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ |
OLD | NEW |