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. | 32 // TODO(msw): Instant support for Win Aura (or --enable-views-textfield). |
33 // | |
34 // LTR support. | |
35 // Drag and drop behavior. | |
36 // Adjust paste behavior (should not autocomplete). | |
37 // Custom context menu for omnibox. | |
38 // Instant. | |
39 class OmniboxViewViews | 33 class OmniboxViewViews |
40 : public views::View, | 34 : public views::Textfield, |
41 public OmniboxView, | 35 public OmniboxView, |
42 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
43 public | 37 public |
44 chromeos::input_method::InputMethodManager::CandidateWindowObserver, | 38 chromeos::input_method::InputMethodManager::CandidateWindowObserver, |
45 #endif | 39 #endif |
46 public views::TextfieldController { | 40 public views::TextfieldController { |
47 public: | 41 public: |
48 // The internal view class name. | 42 // The internal view class name. |
49 static const char kViewClassName[]; | 43 static const char kViewClassName[]; |
50 | 44 |
51 OmniboxViewViews(OmniboxEditController* controller, | 45 OmniboxViewViews(OmniboxEditController* controller, |
52 ToolbarModel* toolbar_model, | 46 ToolbarModel* toolbar_model, |
53 Profile* profile, | 47 Profile* profile, |
54 CommandUpdater* command_updater, | 48 CommandUpdater* command_updater, |
55 bool popup_window_mode, | 49 bool popup_window_mode, |
56 LocationBarView* location_bar); | 50 LocationBarView* location_bar); |
57 virtual ~OmniboxViewViews(); | 51 virtual ~OmniboxViewViews(); |
58 | 52 |
59 // Initialize, create the underlying views, etc; | 53 // Initialize, create the underlying views, etc; |
60 void Init(); | 54 void Init(); |
61 | 55 |
62 // Sets the colors of the text view according to the theme. | 56 // Sets the colors of the text view according to the theme. |
63 void SetBaseColor(); | 57 void SetBaseColor(); |
64 | 58 |
65 // Called after key even is handled either by HandleKeyEvent or by Textfield. | 59 // views::Textfield: |
66 bool HandleAfterKeyEvent(const ui::KeyEvent& event, bool handled); | 60 virtual std::string GetClassName() const OVERRIDE; |
67 | 61 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; | 62 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
94 virtual std::string GetClassName() const OVERRIDE; | |
95 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 63 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
| 64 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
| 65 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; |
| 66 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
| 67 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
| 68 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; |
| 69 virtual void OnFocus() OVERRIDE; |
| 70 virtual void OnBlur() OVERRIDE; |
96 | 71 |
97 // OmniboxView: | 72 // OmniboxView: |
98 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; | 73 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; |
99 virtual void Update( | 74 virtual void Update( |
100 const content::WebContents* tab_for_state_restoring) OVERRIDE; | 75 const content::WebContents* tab_for_state_restoring) OVERRIDE; |
101 virtual string16 GetText() const OVERRIDE; | 76 virtual string16 GetText() const OVERRIDE; |
102 virtual void SetWindowTextAndCaretPos(const string16& text, | 77 virtual void SetWindowTextAndCaretPos(const string16& text, |
103 size_t caret_pos, | 78 size_t caret_pos, |
104 bool update_popup, | 79 bool update_popup, |
105 bool notify_text_changed) OVERRIDE; | 80 bool notify_text_changed) OVERRIDE; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 130 |
156 #if defined(OS_CHROMEOS) | 131 #if defined(OS_CHROMEOS) |
157 // chromeos::input_method::InputMethodManager::CandidateWindowObserver: | 132 // chromeos::input_method::InputMethodManager::CandidateWindowObserver: |
158 virtual void CandidateWindowOpened( | 133 virtual void CandidateWindowOpened( |
159 chromeos::input_method::InputMethodManager* manager) OVERRIDE; | 134 chromeos::input_method::InputMethodManager* manager) OVERRIDE; |
160 virtual void CandidateWindowClosed( | 135 virtual void CandidateWindowClosed( |
161 chromeos::input_method::InputMethodManager* manager) OVERRIDE; | 136 chromeos::input_method::InputMethodManager* manager) OVERRIDE; |
162 #endif | 137 #endif |
163 | 138 |
164 private: | 139 private: |
165 class AutocompleteTextfield; | |
166 | |
167 // Return the number of characers in the current buffer. | 140 // Return the number of characers in the current buffer. |
168 virtual int GetOmniboxTextLength() const OVERRIDE; | 141 virtual int GetOmniboxTextLength() const OVERRIDE; |
169 size_t GetTextLength() const; | |
170 | 142 |
171 // Try to parse the current text as a URL and colorize the components. | 143 // Try to parse the current text as a URL and colorize the components. |
172 virtual void EmphasizeURLComponents() OVERRIDE; | 144 virtual void EmphasizeURLComponents() OVERRIDE; |
173 | 145 |
174 // Update the field with |text| and set the selection. | 146 // Update the field with |text| and set the selection. |
175 void SetTextAndSelectedRange(const string16& text, | 147 void SetTextAndSelectedRange(const string16& text, |
176 const ui::Range& range); | 148 const ui::Range& range); |
177 | 149 |
178 // Returns the selected text. | 150 // Returns the selected text. |
179 string16 GetSelectedText() const; | 151 string16 GetSelectedText() const; |
180 | 152 |
181 // Copy the URL instead of the text in the textfield into clipboard. | 153 // Copy the URL instead of the text in the textfield into clipboard. |
182 void CopyURL(); | 154 void CopyURL(); |
183 | 155 |
184 // Paste text from the clipboard into the omnibox. | 156 // Paste text from the clipboard into the omnibox. |
185 // Textfields implementation of Paste() pastes the contents of the clipboard | 157 // Textfields implementation of Paste() pastes the contents of the clipboard |
186 // as is. We want to strip whitespace and other things (see GetClipboardText() | 158 // as is. We want to strip whitespace and other things (see GetClipboardText() |
187 // for details). | 159 // for details). |
188 // It is assumed this is invoked after a call to OnBeforePossibleChange() and | 160 // It is assumed this is invoked after a call to OnBeforePossibleChange() and |
189 // that after invoking this OnAfterPossibleChange() is invoked. | 161 // that after invoking this OnAfterPossibleChange() is invoked. |
190 void OnPaste(); | 162 void OnPaste(); |
191 | 163 |
192 views::Textfield* textfield_; | |
193 | |
194 // When true, the location bar view is read only and also is has a slightly | 164 // 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. | 165 // different presentation (smaller font size). This is used for popups. |
196 bool popup_window_mode_; | 166 bool popup_window_mode_; |
197 | 167 |
198 scoped_ptr<OmniboxPopupView> popup_view_; | 168 scoped_ptr<OmniboxPopupView> popup_view_; |
199 | 169 |
200 ToolbarModel::SecurityLevel security_level_; | 170 ToolbarModel::SecurityLevel security_level_; |
201 | 171 |
202 // Selection at the point where the user started using the | 172 // Selection at the point where the user started using the |
203 // arrows to move around in the popup. | 173 // arrows to move around in the popup. |
(...skipping 21 matching lines...) Expand all Loading... |
225 | 195 |
226 // Indicates if we want to select all text in the omnibox when we get a | 196 // 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 | 197 // 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. | 198 // and gets a tap. So we use this variable to remember focus state before tap. |
229 bool select_all_on_gesture_tap_; | 199 bool select_all_on_gesture_tap_; |
230 | 200 |
231 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViews); | 201 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViews); |
232 }; | 202 }; |
233 | 203 |
234 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_VIEWS_H_ | 204 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_VIEWS_H_ |
OLD | NEW |