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" | |
21 #include "ui/base/gtk/gtk_signal.h" | 20 #include "ui/base/gtk/gtk_signal.h" |
22 #include "ui/base/gtk/gtk_signal_registrar.h" | 21 #include "ui/base/gtk/gtk_signal_registrar.h" |
23 #include "ui/base/gtk/owned_widget_gtk.h" | 22 #include "ui/base/gtk/owned_widget_gtk.h" |
24 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
25 #include "webkit/glue/window_open_disposition.h" | 24 #include "webkit/glue/window_open_disposition.h" |
26 | 25 |
27 class Browser; | 26 class Browser; |
28 class OmniboxPopupView; | 27 class OmniboxPopupView; |
29 class Profile; | 28 class Profile; |
30 | 29 |
31 namespace gfx { | 30 namespace gfx { |
32 class Font; | 31 class Font; |
33 } | 32 } |
34 | 33 |
35 namespace ui { | |
36 class MultiAnimation; | |
37 } | |
38 | |
39 class GtkThemeService; | 34 class GtkThemeService; |
40 | 35 |
41 class OmniboxViewGtk : public OmniboxView, | 36 class OmniboxViewGtk : public OmniboxView, |
42 public content::NotificationObserver, | 37 public content::NotificationObserver { |
43 public ui::AnimationDelegate { | |
44 public: | 38 public: |
45 // Modeled like the Windows CHARRANGE. Represent a pair of cursor position | 39 // Modeled like the Windows CHARRANGE. Represent a pair of cursor position |
46 // offsets. Since GtkTextIters are invalid after the buffer is changed, we | 40 // offsets. Since GtkTextIters are invalid after the buffer is changed, we |
47 // work in character offsets (not bytes). | 41 // work in character offsets (not bytes). |
48 struct CharRange { | 42 struct CharRange { |
49 CharRange() : cp_min(0), cp_max(0) { } | 43 CharRange() : cp_min(0), cp_max(0) { } |
50 CharRange(int n, int x) : cp_min(n), cp_max(x) { } | 44 CharRange(int n, int x) : cp_min(n), cp_max(x) { } |
51 | 45 |
52 // Returns the start/end of the selection. | 46 // Returns the start/end of the selection. |
53 int selection_min() const { return std::min(cp_min, cp_max); } | 47 int selection_min() const { return std::min(cp_min, cp_max); } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 virtual void OnTemporaryTextMaybeChanged( | 87 virtual void OnTemporaryTextMaybeChanged( |
94 const string16& display_text, | 88 const string16& display_text, |
95 bool save_original_selection) OVERRIDE; | 89 bool save_original_selection) OVERRIDE; |
96 virtual bool OnInlineAutocompleteTextMaybeChanged( | 90 virtual bool OnInlineAutocompleteTextMaybeChanged( |
97 const string16& display_text, size_t user_text_length) OVERRIDE; | 91 const string16& display_text, size_t user_text_length) OVERRIDE; |
98 virtual void OnRevertTemporaryText() OVERRIDE; | 92 virtual void OnRevertTemporaryText() OVERRIDE; |
99 virtual void OnBeforePossibleChange() OVERRIDE; | 93 virtual void OnBeforePossibleChange() OVERRIDE; |
100 virtual bool OnAfterPossibleChange() OVERRIDE; | 94 virtual bool OnAfterPossibleChange() OVERRIDE; |
101 virtual gfx::NativeView GetNativeView() const OVERRIDE; | 95 virtual gfx::NativeView GetNativeView() const OVERRIDE; |
102 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; | 96 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; |
103 virtual void SetInstantSuggestion(const string16& suggestion, | 97 virtual void SetInstantSuggestion(const string16& suggestion) OVERRIDE; |
104 bool animate_to_complete) OVERRIDE; | |
105 virtual string16 GetInstantSuggestion() const OVERRIDE; | 98 virtual string16 GetInstantSuggestion() const OVERRIDE; |
106 virtual int TextWidth() const OVERRIDE; | 99 virtual int TextWidth() const OVERRIDE; |
107 virtual bool IsImeComposing() const OVERRIDE; | 100 virtual bool IsImeComposing() const OVERRIDE; |
108 | 101 |
109 // Overridden from content::NotificationObserver: | 102 // Overridden from content::NotificationObserver: |
110 virtual void Observe(int type, | 103 virtual void Observe(int type, |
111 const content::NotificationSource& source, | 104 const content::NotificationSource& source, |
112 const content::NotificationDetails& details) OVERRIDE; | 105 const content::NotificationDetails& details) OVERRIDE; |
113 | 106 |
114 // Overridden from ui::AnimationDelegate. | |
115 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | |
116 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | |
117 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE; | |
118 | |
119 // Sets the colors of the text view according to the theme. | 107 // Sets the colors of the text view according to the theme. |
120 void SetBaseColor(); | 108 void SetBaseColor(); |
121 // Sets the colors of the instant suggestion view according to the theme and | 109 // Sets the colors of the instant suggestion view according to the theme. |
122 // the animation state. | |
123 void UpdateInstantViewColors(); | 110 void UpdateInstantViewColors(); |
124 | 111 |
125 // Returns the text view gtk widget. May return NULL if the widget | 112 // Returns the text view gtk widget. May return NULL if the widget |
126 // has already been destroyed. | 113 // has already been destroyed. |
127 GtkWidget* text_view() { | 114 GtkWidget* text_view() { |
128 return text_view_; | 115 return text_view_; |
129 } | 116 } |
130 | 117 |
131 private: | 118 private: |
132 CHROMEG_CALLBACK_0(OmniboxViewGtk, void, HandleBeginUserAction, | 119 CHROMEG_CALLBACK_0(OmniboxViewGtk, void, HandleBeginUserAction, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 void GetTextBufferBounds(GtkTextIter* start, GtkTextIter* end) const; | 282 void GetTextBufferBounds(GtkTextIter* start, GtkTextIter* end) const; |
296 | 283 |
297 // Validates an iterator in the |text_buffer_|, to make sure it doesn't go | 284 // Validates an iterator in the |text_buffer_|, to make sure it doesn't go |
298 // beyond the anchor for holding the |instant_view_| widget. | 285 // beyond the anchor for holding the |instant_view_| widget. |
299 void ValidateTextBufferIter(GtkTextIter* iter) const; | 286 void ValidateTextBufferIter(GtkTextIter* iter) const; |
300 | 287 |
301 // Adjusts vertical alignment of the |instant_view_| in the |text_view_|, to | 288 // Adjusts vertical alignment of the |instant_view_| in the |text_view_|, to |
302 // make sure they have the same baseline. | 289 // make sure they have the same baseline. |
303 void AdjustVerticalAlignmentOfInstantView(); | 290 void AdjustVerticalAlignmentOfInstantView(); |
304 | 291 |
305 // Stop showing the instant suggest auto-commit animation. | |
306 void StopAnimation(); | |
307 | |
308 // The Browser that contains this omnibox. | 292 // The Browser that contains this omnibox. |
309 Browser* browser_; | 293 Browser* browser_; |
310 | 294 |
311 // The widget we expose, used for vertically centering the real text edit, | 295 // The widget we expose, used for vertically centering the real text edit, |
312 // since the height will change based on the font / font size, etc. | 296 // since the height will change based on the font / font size, etc. |
313 ui::OwnedWidgetGtk alignment_; | 297 ui::OwnedWidgetGtk alignment_; |
314 | 298 |
315 // The actual text entry which will be owned by the alignment_. The | 299 // The actual text entry which will be owned by the alignment_. The |
316 // reference will be set to NULL upon destruction to tell if the gtk | 300 // reference will be set to NULL upon destruction to tell if the gtk |
317 // widget tree has been destroyed. This is because gtk destroies child | 301 // widget tree has been destroyed. This is because gtk destroies child |
318 // widgets if the parent (alignemtn_)'s refcount does not go down to 0. | 302 // widgets if the parent (alignemtn_)'s refcount does not go down to 0. |
319 GtkWidget* text_view_; | 303 GtkWidget* text_view_; |
320 | 304 |
321 GtkTextTagTable* tag_table_; | 305 GtkTextTagTable* tag_table_; |
322 GtkTextBuffer* text_buffer_; | 306 GtkTextBuffer* text_buffer_; |
323 GtkTextTag* faded_text_tag_; | 307 GtkTextTag* faded_text_tag_; |
324 GtkTextTag* secure_scheme_tag_; | 308 GtkTextTag* secure_scheme_tag_; |
325 GtkTextTag* security_error_scheme_tag_; | 309 GtkTextTag* security_error_scheme_tag_; |
326 GtkTextTag* normal_text_tag_; | 310 GtkTextTag* normal_text_tag_; |
327 | 311 |
328 // Objects for the instant suggestion text view. | 312 // Objects for the instant suggestion text view. |
329 GtkTextTag* instant_anchor_tag_; | 313 GtkTextTag* instant_anchor_tag_; |
330 | 314 |
331 // A widget for displaying instant suggestion text. It'll be attached to a | 315 // A widget for displaying instant suggestion text. It'll be attached to a |
332 // child anchor in the |text_buffer_| object. | 316 // child anchor in the |text_buffer_| object. |
333 GtkWidget* instant_view_; | 317 GtkWidget* instant_view_; |
334 // Animation from instant suggest (faded text) to autocomplete (selected | |
335 // text). | |
336 scoped_ptr<ui::MultiAnimation> instant_animation_; | |
337 | 318 |
338 // A mark to split the content and the instant anchor. Wherever the end | 319 // A mark to split the content and the instant anchor. Wherever the end |
339 // iterator of the text buffer is required, the iterator to this mark should | 320 // iterator of the text buffer is required, the iterator to this mark should |
340 // be used. | 321 // be used. |
341 GtkTextMark* instant_mark_; | 322 GtkTextMark* instant_mark_; |
342 | 323 |
343 scoped_ptr<OmniboxPopupView> popup_view_; | 324 scoped_ptr<OmniboxPopupView> popup_view_; |
344 | 325 |
345 // When true, the location bar view is read only and also is has a slightly | 326 // When true, the location bar view is read only and also is has a slightly |
346 // different presentation (smaller font size). This is used for popups. | 327 // different presentation (smaller font size). This is used for popups. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 // The view that is going to be focused next. Only valid while handling | 445 // The view that is going to be focused next. Only valid while handling |
465 // "focus-out" events. | 446 // "focus-out" events. |
466 GtkWidget* going_to_focus_; | 447 GtkWidget* going_to_focus_; |
467 | 448 |
468 ui::GtkSignalRegistrar signals_; | 449 ui::GtkSignalRegistrar signals_; |
469 | 450 |
470 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtk); | 451 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtk); |
471 }; | 452 }; |
472 | 453 |
473 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ | 454 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_VIEW_GTK_H_ |
OLD | NEW |