OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_ |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_ |
| 7 |
| 8 #include <gtk/gtk.h> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/scoped_ptr.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 14 #include "chrome/browser/toolbar_model.h" |
| 15 #include "chrome/common/page_transition_types.h" |
| 16 #include "webkit/glue/window_open_disposition.h" |
| 17 |
| 18 class AutocompleteEditController; |
| 19 class AutocompleteEditModel; |
| 20 class AutocompletePopupViewGtk; |
| 21 class CommandUpdater; |
| 22 class Profile; |
| 23 class TabContents; |
| 24 class ToolbarModel; |
| 25 |
| 26 class AutocompleteEditViewGtk : public AutocompleteEditView { |
| 27 public: |
| 28 AutocompleteEditViewGtk(AutocompleteEditController* controller, |
| 29 ToolbarModel* toolbar_model, |
| 30 Profile* profile, |
| 31 CommandUpdater* command_updater); |
| 32 ~AutocompleteEditViewGtk(); |
| 33 |
| 34 // Initialize, create the underlying widgets, etc. |
| 35 void Init(); |
| 36 |
| 37 GtkWidget* widget() { return text_view_; } |
| 38 |
| 39 // Grab keyboard input focus, putting focus on the location widget. |
| 40 void FocusLocation(); |
| 41 |
| 42 // Implement the AutocompleteEditView interface. |
| 43 virtual AutocompleteEditModel* model() { return model_.get(); } |
| 44 virtual const AutocompleteEditModel* model() const { return model_.get(); } |
| 45 |
| 46 virtual void SaveStateToTab(TabContents* tab); |
| 47 |
| 48 virtual void Update(const TabContents* tab_for_state_restoring); |
| 49 |
| 50 virtual void OpenURL(const GURL& url, |
| 51 WindowOpenDisposition disposition, |
| 52 PageTransition::Type transition, |
| 53 const GURL& alternate_nav_url, |
| 54 size_t selected_line, |
| 55 const std::wstring& keyword); |
| 56 |
| 57 virtual std::wstring GetText() const; |
| 58 |
| 59 virtual void SetUserText(const std::wstring& text) { |
| 60 SetUserText(text, text, true); |
| 61 } |
| 62 virtual void SetUserText(const std::wstring& text, |
| 63 const std::wstring& display_text, |
| 64 bool update_popup); |
| 65 |
| 66 virtual void SetWindowTextAndCaretPos(const std::wstring& text, |
| 67 size_t caret_pos); |
| 68 |
| 69 virtual bool IsSelectAll(); |
| 70 virtual void SelectAll(bool reversed); |
| 71 virtual void RevertAll(); |
| 72 |
| 73 virtual void UpdatePopup(); |
| 74 virtual void ClosePopup(); |
| 75 |
| 76 virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, |
| 77 bool save_original_selection); |
| 78 virtual bool OnInlineAutocompleteTextMaybeChanged( |
| 79 const std::wstring& display_text, size_t user_text_length); |
| 80 virtual void OnRevertTemporaryText(); |
| 81 virtual void OnBeforePossibleChange(); |
| 82 virtual bool OnAfterPossibleChange(); |
| 83 |
| 84 // Return the position (root coordinates) of the bottom left corner and width |
| 85 // of the location input box. Used by the popup view to position itself. |
| 86 void BottomLeftPosWidth(int* x, int* y, int* width); |
| 87 |
| 88 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. |
| 102 static void HandleBeginUserActionThunk(GtkTextBuffer* unused, gpointer self) { |
| 103 reinterpret_cast<AutocompleteEditViewGtk*>(self)->HandleBeginUserAction(); |
| 104 } |
| 105 void HandleBeginUserAction(); |
| 106 |
| 107 static void HandleEndUserActionThunk(GtkTextBuffer* unused, gpointer self) { |
| 108 reinterpret_cast<AutocompleteEditViewGtk*>(self)->HandleEndUserAction(); |
| 109 } |
| 110 void HandleEndUserAction(); |
| 111 |
| 112 static void HandleViewSizeRequest(GtkWidget* view, GtkRequisition* req, |
| 113 gpointer unused); |
| 114 |
| 115 static gboolean HandleViewButtonPressThunk(GtkWidget* view, |
| 116 GdkEventButton* event, |
| 117 gpointer self) { |
| 118 return reinterpret_cast<AutocompleteEditViewGtk*>(self)-> |
| 119 HandleViewButtonPress(event); |
| 120 } |
| 121 gboolean HandleViewButtonPress(GdkEventButton* event); |
| 122 |
| 123 static gboolean HandleViewFocusInThunk(GtkWidget* view, |
| 124 GdkEventFocus* event, |
| 125 gpointer self) { |
| 126 return reinterpret_cast<AutocompleteEditViewGtk*>(self)-> |
| 127 HandleViewFocusIn(); |
| 128 } |
| 129 gboolean HandleViewFocusIn(); |
| 130 |
| 131 static gboolean HandleViewFocusOutThunk(GtkWidget* view, |
| 132 GdkEventFocus* event, |
| 133 gpointer self) { |
| 134 return reinterpret_cast<AutocompleteEditViewGtk*>(self)-> |
| 135 HandleViewFocusOut(); |
| 136 } |
| 137 gboolean HandleViewFocusOut(); |
| 138 |
| 139 static void HandleViewMoveCursorThunk(GtkWidget* view, |
| 140 GtkMovementStep step, |
| 141 gint count, |
| 142 gboolean extend_selection, |
| 143 gpointer self) { |
| 144 reinterpret_cast<AutocompleteEditViewGtk*>(self)-> |
| 145 HandleViewMoveCursor(step, count, extend_selection); |
| 146 } |
| 147 void HandleViewMoveCursor(GtkMovementStep step, |
| 148 gint count, |
| 149 gboolean extendion_selection); |
| 150 |
| 151 // Get the character indices of the current selection. This honors |
| 152 // direction, cp_max is the insertion point, and cp_min is the bound. |
| 153 CharRange GetSelection(); |
| 154 |
| 155 // Translate from character positions to iterators for the current buffer. |
| 156 void ItersFromCharRange(const CharRange& range, |
| 157 GtkTextIter* iter_min, |
| 158 GtkTextIter* iter_max); |
| 159 |
| 160 // Return the number of characers in the current buffer. |
| 161 int GetTextLength(); |
| 162 |
| 163 // Try to parse the current text as a URL and colorize the components. |
| 164 void EmphasizeURLComponents(); |
| 165 |
| 166 // Internally invoked whenever the text changes in some way. |
| 167 void TextChanged(); |
| 168 |
| 169 GtkWidget* text_view_; |
| 170 |
| 171 GtkTextTagTable* tag_table_; |
| 172 GtkTextBuffer* text_buffer_; |
| 173 |
| 174 GtkTextTag* base_tag_; |
| 175 GtkTextTag* secure_scheme_tag_; |
| 176 GtkTextTag* insecure_scheme_tag_; |
| 177 |
| 178 scoped_ptr<AutocompleteEditModel> model_; |
| 179 scoped_ptr<AutocompletePopupViewGtk> popup_view_; |
| 180 AutocompleteEditController* controller_; |
| 181 ToolbarModel* toolbar_model_; |
| 182 |
| 183 // The object that handles additional command functionality exposed on the |
| 184 // edit, such as invoking the keyword editor. |
| 185 CommandUpdater* command_updater_; |
| 186 |
| 187 // When true, the location bar view is read only and also is has a slightly |
| 188 // different presentation (font size / color). This is used for popups. |
| 189 // TODO(deanm). |
| 190 bool popup_window_mode_; |
| 191 |
| 192 ToolbarModel::SecurityLevel scheme_security_level_; |
| 193 |
| 194 // Tracking state before and after a possible change. |
| 195 std::wstring text_before_change_; |
| 196 CharRange sel_before_change_; |
| 197 |
| 198 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewGtk); |
| 199 }; |
| 200 |
| 201 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_GTK_H_ |
OLD | NEW |