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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 guint info); | 216 guint info); |
234 | 217 |
235 void HandleCopyOrCutClipboard(bool copy); | 218 void HandleCopyOrCutClipboard(bool copy); |
236 | 219 |
237 // Common implementation for performing a drop on the edit view. | 220 // Common implementation for performing a drop on the edit view. |
238 bool OnPerformDropImpl(const string16& text); | 221 bool OnPerformDropImpl(const string16& text); |
239 | 222 |
240 // Returns the font used in |text_view_|. | 223 // Returns the font used in |text_view_|. |
241 gfx::Font GetFont(); | 224 gfx::Font GetFont(); |
242 | 225 |
| 226 // OmniboxView overrides |
| 227 // Return the number of characters in the current buffer. |
| 228 virtual int GetOmniboxTextLength() const OVERRIDE; |
| 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); |
247 | 234 |
248 // Gets the GTK_TEXT_WINDOW_WIDGET coordinates for |text_view_| that bound the | 235 // Gets the GTK_TEXT_WINDOW_WIDGET coordinates for |text_view_| that bound the |
249 // given iters. | 236 // given iters. |
250 gfx::Rect WindowBoundsFromIters(GtkTextIter* iter1, GtkTextIter* iter2); | 237 gfx::Rect WindowBoundsFromIters(GtkTextIter* iter1, GtkTextIter* iter2); |
251 | 238 |
252 // Actual implementation of SelectAll(), but also provides control over | 239 // Actual implementation of SelectAll(), but also provides control over |
(...skipping 13 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. | 266 // Try to parse the current text as a URL and colorize the components. |
286 void EmphasizeURLComponents(); | 267 virtual void EmphasizeURLComponents() OVERRIDE; |
287 | |
288 // Internally invoked whenever the text changes in some way. | |
289 void TextChanged(); | |
290 | 268 |
291 // Save |selected_text| as the PRIMARY X selection. Unlike | 269 // Save |selected_text| as the PRIMARY X selection. Unlike |
292 // OwnPrimarySelection(), this won't set an owner or use callbacks. | 270 // OwnPrimarySelection(), this won't set an owner or use callbacks. |
293 void SavePrimarySelection(const std::string& selected_text); | 271 void SavePrimarySelection(const std::string& selected_text); |
294 | 272 |
295 // Update the field with |text| and set the selection. | 273 // Update the field with |text| and set the selection. |
296 void SetTextAndSelectedRange(const string16& text, | 274 void SetTextAndSelectedRange(const string16& text, |
297 const CharRange& range); | 275 const CharRange& range); |
298 | 276 |
299 // Set the selection to |range|. | 277 // Set the selection to |range|. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 GtkWidget* instant_view_; | 335 GtkWidget* instant_view_; |
358 // Animation from instant suggest (faded text) to autocomplete (selected | 336 // Animation from instant suggest (faded text) to autocomplete (selected |
359 // text). | 337 // text). |
360 scoped_ptr<ui::MultiAnimation> instant_animation_; | 338 scoped_ptr<ui::MultiAnimation> instant_animation_; |
361 | 339 |
362 // A mark to split the content and the instant anchor. Wherever the end | 340 // 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 | 341 // iterator of the text buffer is required, the iterator to this mark should |
364 // be used. | 342 // be used. |
365 GtkTextMark* instant_mark_; | 343 GtkTextMark* instant_mark_; |
366 | 344 |
367 scoped_ptr<OmniboxEditModel> model_; | |
368 scoped_ptr<OmniboxPopupView> popup_view_; | 345 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 | 346 |
376 // When true, the location bar view is read only and also is has a slightly | 347 // 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. | 348 // different presentation (smaller font size). This is used for popups. |
378 bool popup_window_mode_; | 349 bool popup_window_mode_; |
379 | 350 |
380 ToolbarModel::SecurityLevel security_level_; | 351 ToolbarModel::SecurityLevel security_level_; |
381 | 352 |
382 // Selection at the point where the user started using the | 353 // Selection at the point where the user started using the |
383 // arrows to move around in the popup. | 354 // arrows to move around in the popup. |
384 CharRange saved_temporary_selection_; | 355 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 | 466 // The view that is going to be focused next. Only valid while handling |
496 // "focus-out" events. | 467 // "focus-out" events. |
497 GtkWidget* going_to_focus_; | 468 GtkWidget* going_to_focus_; |
498 | 469 |
499 ui::GtkSignalRegistrar signals_; | 470 ui::GtkSignalRegistrar signals_; |
500 | 471 |
501 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtk); | 472 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtk); |
502 }; | 473 }; |
503 | 474 |
504 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ | 475 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ |
OLD | NEW |