OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_VIEWS_H_ |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_VIEWS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/scoped_ptr.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 14 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 15 #include "chrome/common/notification_observer.h" |
| 16 #include "chrome/common/notification_registrar.h" |
| 17 #include "chrome/common/page_transition_types.h" |
| 18 #include "views/controls/textfield/textfield.h" |
| 19 #include "views/view.h" |
| 20 #include "webkit/glue/window_open_disposition.h" |
| 21 |
| 22 class AutocompleteEditController; |
| 23 class AutocompleteEditModel; |
| 24 class AutocompletePopupView; |
| 25 class Profile; |
| 26 class TabContents; |
| 27 |
| 28 // Views-implementation of AutocompleteEditView. This is based on |
| 29 // gtk implementation. The following features are not yet supported. |
| 30 // |
| 31 // IME supoprt. |
| 32 // LTR support. |
| 33 // Selection behavior. |
| 34 // Cut,copy and paste behavior. |
| 35 // URL styles (strikestrough insecure scheme, emphasize host). |
| 36 // Custom context menu for omnibox. |
| 37 // Instant. |
| 38 class AutocompleteEditViewViews : public views::View, |
| 39 public AutocompleteEditView, |
| 40 public NotificationObserver, |
| 41 public views::Textfield::Controller { |
| 42 public: |
| 43 AutocompleteEditViewViews(AutocompleteEditController* controller, |
| 44 ToolbarModel* toolbar_model, |
| 45 Profile* profile, |
| 46 CommandUpdater* command_updater, |
| 47 bool popup_window_mode, |
| 48 const views::View* location_bar); |
| 49 virtual ~AutocompleteEditViewViews(); |
| 50 |
| 51 // Initialize, create the underlying views, etc; |
| 52 void Init(); |
| 53 |
| 54 // Sets the colors of the text view according to the theme. |
| 55 void SetBaseColor(); |
| 56 |
| 57 // Called after key even is handled either by HandleKeyEvent or by Textfield. |
| 58 bool HandleAfterKeyEvent(const views::KeyEvent& event, bool handled); |
| 59 |
| 60 // Called when KeyRelease event is generated on textfield. |
| 61 bool HandleKeyReleaseEvent(const views::KeyEvent& event); |
| 62 |
| 63 // Called when Focus is set/unset on textfield. |
| 64 void HandleFocusIn(); |
| 65 void HandleFocusOut(); |
| 66 |
| 67 // Implements views::View |
| 68 virtual bool OnMousePressed(const views::MouseEvent& event); |
| 69 virtual void Layout(); |
| 70 |
| 71 // Implement the AutocompleteEditView interface. |
| 72 virtual AutocompleteEditModel* model(); |
| 73 virtual const AutocompleteEditModel* model() const; |
| 74 |
| 75 virtual void SaveStateToTab(TabContents* tab); |
| 76 |
| 77 virtual void Update(const TabContents* tab_for_state_restoring); |
| 78 |
| 79 virtual void OpenURL(const GURL& url, |
| 80 WindowOpenDisposition disposition, |
| 81 PageTransition::Type transition, |
| 82 const GURL& alternate_nav_url, |
| 83 size_t selected_line, |
| 84 const std::wstring& keyword); |
| 85 |
| 86 virtual std::wstring GetText() const; |
| 87 |
| 88 virtual bool IsEditingOrEmpty() const; |
| 89 virtual int GetIcon() const; |
| 90 virtual void SetUserText(const std::wstring& text); |
| 91 virtual void SetUserText(const std::wstring& text, |
| 92 const std::wstring& display_text, |
| 93 bool update_popup); |
| 94 virtual void SetWindowTextAndCaretPos(const std::wstring& text, |
| 95 size_t caret_pos); |
| 96 virtual void SetForcedQuery(); |
| 97 virtual bool IsSelectAll(); |
| 98 virtual bool DeleteAtEndPressed(); |
| 99 virtual void GetSelectionBounds(std::wstring::size_type* start, |
| 100 std::wstring::size_type* end); |
| 101 virtual void SelectAll(bool reversed); |
| 102 virtual void RevertAll(); |
| 103 virtual void UpdatePopup(); |
| 104 virtual void ClosePopup(); |
| 105 virtual void SetFocus(); |
| 106 virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, |
| 107 bool save_original_selection); |
| 108 virtual bool OnInlineAutocompleteTextMaybeChanged( |
| 109 const std::wstring& display_text, size_t user_text_length); |
| 110 virtual void OnRevertTemporaryText(); |
| 111 virtual void OnBeforePossibleChange(); |
| 112 virtual bool OnAfterPossibleChange(); |
| 113 virtual gfx::NativeView GetNativeView() const; |
| 114 virtual CommandUpdater* GetCommandUpdater(); |
| 115 virtual views::View* AddToView(views::View* parent); |
| 116 virtual int TextWidth() const; |
| 117 virtual bool IsImeComposing() const; |
| 118 virtual bool CommitInstantSuggestion(const std::wstring& typed_text, |
| 119 const std::wstring& suggested_text); |
| 120 virtual void SetInstantSuggestion(const string16& input); |
| 121 |
| 122 // Overridden from NotificationObserver: |
| 123 virtual void Observe(NotificationType type, |
| 124 const NotificationSource& source, |
| 125 const NotificationDetails& details); |
| 126 |
| 127 // Overridden from Textfield::Controller |
| 128 virtual void ContentsChanged(views::Textfield* sender, |
| 129 const string16& new_contents); |
| 130 virtual bool HandleKeyEvent(views::Textfield* sender, |
| 131 const views::KeyEvent& key_event); |
| 132 |
| 133 private: |
| 134 // Return the number of characers in the current buffer. |
| 135 size_t GetTextLength() const; |
| 136 |
| 137 // Try to parse the current text as a URL and colorize the components. |
| 138 void EmphasizeURLComponents(); |
| 139 |
| 140 // Internally invoked whenever the text changes in some way. |
| 141 void TextChanged(); |
| 142 |
| 143 // Update the field with |text| and set the selection. |
| 144 void SetTextAndSelectedRange(const std::wstring& text, |
| 145 const views::TextRange& range); |
| 146 |
| 147 // Returns the selected text. |
| 148 string16 GetSelectedText() const; |
| 149 |
| 150 // Selects the text given by |caret| and |end|. |
| 151 void SelectRange(size_t caret, size_t end); |
| 152 |
| 153 views::Textfield* textfield_; |
| 154 |
| 155 scoped_ptr<AutocompleteEditModel> model_; |
| 156 scoped_ptr<AutocompletePopupView> popup_view_; |
| 157 AutocompleteEditController* controller_; |
| 158 ToolbarModel* toolbar_model_; |
| 159 |
| 160 // The object that handles additional command functionality exposed on the |
| 161 // edit, such as invoking the keyword editor. |
| 162 CommandUpdater* command_updater_; |
| 163 |
| 164 // When true, the location bar view is read only and also is has a slightly |
| 165 // different presentation (smaller font size). This is used for popups. |
| 166 bool popup_window_mode_; |
| 167 |
| 168 ToolbarModel::SecurityLevel security_level_; |
| 169 |
| 170 // Selection at the point where the user started using the |
| 171 // arrows to move around in the popup. |
| 172 views::TextRange saved_temporary_selection_; |
| 173 |
| 174 // Tracking state before and after a possible change. |
| 175 std::wstring text_before_change_; |
| 176 views::TextRange sel_before_change_; |
| 177 |
| 178 // TODO(oshima): following flags are copied from gtk implementation. |
| 179 // It should be possible to refactor this class to simplify flags and |
| 180 // logic. I'll work on this refactoring once all features are completed. |
| 181 |
| 182 // Indicates whether the IME changed the text. It's possible for the IME to |
| 183 // handle a key event but not change the text contents (e.g., when pressing |
| 184 // shift+del with no selection). |
| 185 bool text_changed_; |
| 186 |
| 187 // Was delete pressed? |
| 188 bool delete_was_pressed_; |
| 189 |
| 190 // Was the delete key pressed with an empty selection at the end of the edit? |
| 191 bool delete_at_end_pressed_; |
| 192 |
| 193 // Indicates if we are handling a key press event. |
| 194 bool handling_key_press_; |
| 195 |
| 196 // Indicates if omnibox's content maybe changed by a key press event, so that |
| 197 // we need to call OnAfterPossibleChange() after handling the event. |
| 198 // This flag should be set for changes directly caused by a key press event, |
| 199 // including changes to content text, selection range and preedit string. |
| 200 // Changes caused by function calls like SetUserText() should not affect this |
| 201 // flag. |
| 202 bool content_maybe_changed_by_key_press_; |
| 203 |
| 204 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewViews); |
| 205 }; |
| 206 |
| 207 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_VIEWS_H_ |
OLD | NEW |