Chromium Code Reviews| 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_VIEWS_OMNIBOX_OMNIBOX_VIEW_VIEWS_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_VIEWS_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_VIEWS_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_VIEWS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 12 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 13 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 13 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 14 #include "ui/base/range/range.h" | 14 #include "ui/base/range/range.h" |
| 15 #include "ui/base/window_open_disposition.h" | 15 #include "ui/base/window_open_disposition.h" |
| 16 #include "ui/views/controls/textfield/textfield.h" | |
| 16 #include "ui/views/controls/textfield/textfield_controller.h" | 17 #include "ui/views/controls/textfield/textfield_controller.h" |
| 17 #include "ui/views/view.h" | |
| 18 | 18 |
| 19 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
| 20 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 20 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 class LocationBarView; | 23 class LocationBarView; |
| 24 class OmniboxPopupView; | 24 class OmniboxPopupView; |
| 25 class Profile; | 25 class Profile; |
| 26 | 26 |
| 27 namespace ui { | 27 namespace ui { |
| 28 class OSExchangeData; | 28 class OSExchangeData; |
| 29 } // namespace ui | 29 } // namespace ui |
| 30 | 30 |
| 31 // Views-implementation of OmniboxView. This is based on gtk implementation. | 31 // Views-implementation of OmniboxView. This is based on gtk implementation. |
| 32 // The following features are not yet supported. | |
| 33 // | |
| 34 // LTR support. | |
| 35 // Drag and drop behavior. | |
| 36 // Adjust paste behavior (should not autocomplete). | |
| 37 // Custom context menu for omnibox. | |
| 38 // Instant. | |
|
Peter Kasting
2013/02/18 18:57:47
Are these all fixed, then?
msw
2013/02/18 20:58:21
All of these are supported except perhaps Instant,
| |
| 39 class OmniboxViewViews | 32 class OmniboxViewViews |
| 40 : public views::View, | 33 : public views::Textfield, |
| 41 public OmniboxView, | 34 public OmniboxView, |
| 42 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 43 public | 36 public |
| 44 chromeos::input_method::InputMethodManager::CandidateWindowObserver, | 37 chromeos::input_method::InputMethodManager::CandidateWindowObserver, |
| 45 #endif | 38 #endif |
| 46 public views::TextfieldController { | 39 public views::TextfieldController { |
| 47 public: | 40 public: |
| 48 // The internal view class name. | 41 // The internal view class name. |
| 49 static const char kViewClassName[]; | 42 static const char kViewClassName[]; |
| 50 | 43 |
| 51 OmniboxViewViews(OmniboxEditController* controller, | 44 OmniboxViewViews(OmniboxEditController* controller, |
| 52 ToolbarModel* toolbar_model, | 45 ToolbarModel* toolbar_model, |
| 53 Profile* profile, | 46 Profile* profile, |
| 54 CommandUpdater* command_updater, | 47 CommandUpdater* command_updater, |
| 55 bool popup_window_mode, | 48 bool popup_window_mode, |
| 56 LocationBarView* location_bar); | 49 LocationBarView* location_bar); |
| 57 virtual ~OmniboxViewViews(); | 50 virtual ~OmniboxViewViews(); |
| 58 | 51 |
| 59 // Initialize, create the underlying views, etc; | 52 // Initialize, create the underlying views, etc; |
| 60 void Init(); | 53 void Init(); |
| 61 | 54 |
| 62 // Sets the colors of the text view according to the theme. | 55 // Sets the colors of the text view according to the theme. |
| 63 void SetBaseColor(); | 56 void SetBaseColor(); |
| 64 | 57 |
| 65 // Called after key even is handled either by HandleKeyEvent or by Textfield. | 58 // views::View: |
|
Peter Kasting
2013/02/18 18:57:47
Nit: We don't directly override View, perhaps this
msw
2013/02/18 20:58:21
Done.
| |
| 66 bool HandleAfterKeyEvent(const ui::KeyEvent& event, bool handled); | 59 virtual std::string GetClassName() const OVERRIDE; |
| 67 | 60 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 68 // Called when KeyRelease event is generated on textfield. | |
| 69 bool HandleKeyReleaseEvent(const ui::KeyEvent& event); | |
| 70 | |
| 71 // Called when mouse events are generated on the textfield. | |
| 72 // The views::Textfield implementations will be executed first. | |
| 73 void HandleMousePressEvent(const ui::MouseEvent& event); | |
| 74 void HandleMouseDragEvent(const ui::MouseEvent& event); | |
| 75 void HandleMouseReleaseEvent(const ui::MouseEvent& event); | |
| 76 | |
| 77 // Called when a gesture event is generated on textfield. | |
| 78 void HandleGestureEvent(const ui::GestureEvent& event); | |
| 79 | |
| 80 // Called when Focus is set/unset on textfield. | |
| 81 void HandleFocusIn(); | |
| 82 void HandleFocusOut(); | |
| 83 | |
| 84 // Sets whether the location entry can accept focus. | |
| 85 void SetLocationEntryFocusable(bool focusable); | |
| 86 | |
| 87 // Returns true if the location entry is focusable and visible in | |
| 88 // the root view. | |
| 89 bool IsLocationEntryFocusableInRootView() const; | |
| 90 | |
| 91 // Implements views::View | |
| 92 virtual void Layout() OVERRIDE; | |
| 93 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 61 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 94 virtual std::string GetClassName() const OVERRIDE; | |
| 95 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 62 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
| 63 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | |
| 64 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; | |
| 65 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | |
| 66 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | |
| 67 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; | |
| 68 virtual void OnFocus() OVERRIDE; | |
| 69 virtual void OnBlur() OVERRIDE; | |
| 96 | 70 |
| 97 // OmniboxView: | 71 // OmniboxView: |
| 98 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; | 72 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; |
| 99 virtual void Update( | 73 virtual void Update( |
| 100 const content::WebContents* tab_for_state_restoring) OVERRIDE; | 74 const content::WebContents* tab_for_state_restoring) OVERRIDE; |
| 101 virtual string16 GetText() const OVERRIDE; | 75 virtual string16 GetText() const OVERRIDE; |
| 102 virtual void SetWindowTextAndCaretPos(const string16& text, | 76 virtual void SetWindowTextAndCaretPos(const string16& text, |
| 103 size_t caret_pos, | 77 size_t caret_pos, |
| 104 bool update_popup, | 78 bool update_popup, |
| 105 bool notify_text_changed) OVERRIDE; | 79 bool notify_text_changed) OVERRIDE; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 | 129 |
| 156 #if defined(OS_CHROMEOS) | 130 #if defined(OS_CHROMEOS) |
| 157 // chromeos::input_method::InputMethodManager::CandidateWindowObserver: | 131 // chromeos::input_method::InputMethodManager::CandidateWindowObserver: |
| 158 virtual void CandidateWindowOpened( | 132 virtual void CandidateWindowOpened( |
| 159 chromeos::input_method::InputMethodManager* manager) OVERRIDE; | 133 chromeos::input_method::InputMethodManager* manager) OVERRIDE; |
| 160 virtual void CandidateWindowClosed( | 134 virtual void CandidateWindowClosed( |
| 161 chromeos::input_method::InputMethodManager* manager) OVERRIDE; | 135 chromeos::input_method::InputMethodManager* manager) OVERRIDE; |
| 162 #endif | 136 #endif |
| 163 | 137 |
| 164 private: | 138 private: |
| 165 class AutocompleteTextfield; | |
| 166 | |
| 167 // Return the number of characers in the current buffer. | 139 // Return the number of characers in the current buffer. |
| 168 virtual int GetOmniboxTextLength() const OVERRIDE; | 140 virtual int GetOmniboxTextLength() const OVERRIDE; |
| 169 size_t GetTextLength() const; | |
| 170 | 141 |
| 171 // Try to parse the current text as a URL and colorize the components. | 142 // Try to parse the current text as a URL and colorize the components. |
| 172 virtual void EmphasizeURLComponents() OVERRIDE; | 143 virtual void EmphasizeURLComponents() OVERRIDE; |
| 173 | 144 |
| 174 // Update the field with |text| and set the selection. | 145 // Update the field with |text| and set the selection. |
| 175 void SetTextAndSelectedRange(const string16& text, | 146 void SetTextAndSelectedRange(const string16& text, |
| 176 const ui::Range& range); | 147 const ui::Range& range); |
| 177 | 148 |
| 178 // Returns the selected text. | 149 // Returns the selected text. |
| 179 string16 GetSelectedText() const; | 150 string16 GetSelectedText() const; |
| 180 | 151 |
| 181 // Copy the URL instead of the text in the textfield into clipboard. | 152 // Copy the URL instead of the text in the textfield into clipboard. |
| 182 void CopyURL(); | 153 void CopyURL(); |
| 183 | 154 |
| 184 // Paste text from the clipboard into the omnibox. | 155 // Paste text from the clipboard into the omnibox. |
| 185 // Textfields implementation of Paste() pastes the contents of the clipboard | 156 // Textfields implementation of Paste() pastes the contents of the clipboard |
| 186 // as is. We want to strip whitespace and other things (see GetClipboardText() | 157 // as is. We want to strip whitespace and other things (see GetClipboardText() |
| 187 // for details). | 158 // for details). |
| 188 // It is assumed this is invoked after a call to OnBeforePossibleChange() and | 159 // It is assumed this is invoked after a call to OnBeforePossibleChange() and |
| 189 // that after invoking this OnAfterPossibleChange() is invoked. | 160 // that after invoking this OnAfterPossibleChange() is invoked. |
| 190 void OnPaste(); | 161 void OnPaste(); |
| 191 | 162 |
| 192 views::Textfield* textfield_; | |
| 193 | |
| 194 // When true, the location bar view is read only and also is has a slightly | 163 // When true, the location bar view is read only and also is has a slightly |
| 195 // different presentation (smaller font size). This is used for popups. | 164 // different presentation (smaller font size). This is used for popups. |
| 196 bool popup_window_mode_; | 165 bool popup_window_mode_; |
| 197 | 166 |
| 198 scoped_ptr<OmniboxPopupView> popup_view_; | 167 scoped_ptr<OmniboxPopupView> popup_view_; |
| 199 | 168 |
| 200 ToolbarModel::SecurityLevel security_level_; | 169 ToolbarModel::SecurityLevel security_level_; |
| 201 | 170 |
| 202 // Selection at the point where the user started using the | 171 // Selection at the point where the user started using the |
| 203 // arrows to move around in the popup. | 172 // arrows to move around in the popup. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 225 | 194 |
| 226 // Indicates if we want to select all text in the omnibox when we get a | 195 // Indicates if we want to select all text in the omnibox when we get a |
| 227 // GESTURE_TAP. We want to select all only when the textfield is not in focus | 196 // GESTURE_TAP. We want to select all only when the textfield is not in focus |
| 228 // and gets a tap. So we use this variable to remember focus state before tap. | 197 // and gets a tap. So we use this variable to remember focus state before tap. |
| 229 bool select_all_on_gesture_tap_; | 198 bool select_all_on_gesture_tap_; |
| 230 | 199 |
| 231 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViews); | 200 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViews); |
| 232 }; | 201 }; |
| 233 | 202 |
| 234 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_VIEWS_H_ | 203 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_VIEWS_H_ |
| OLD | NEW |