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