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 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
6 | 6 |
7 #include "base/property_bag.h" | 7 #include "base/property_bag.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE { | 80 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE { |
81 bool handled = views::Textfield::OnKeyPressed(event); | 81 bool handled = views::Textfield::OnKeyPressed(event); |
82 return omnibox_view_->HandleAfterKeyEvent(event, handled) || handled; | 82 return omnibox_view_->HandleAfterKeyEvent(event, handled) || handled; |
83 } | 83 } |
84 | 84 |
85 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE { | 85 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE { |
86 return omnibox_view_->HandleKeyReleaseEvent(event); | 86 return omnibox_view_->HandleKeyReleaseEvent(event); |
87 } | 87 } |
88 | 88 |
89 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { | 89 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { |
90 return omnibox_view_->HandleMousePressEvent(event); | 90 bool result = views::Textfield::OnMousePressed(event); |
Daniel Erat
2012/05/16 21:06:02
Textfield doesn't implement these (yet), but I fig
| |
91 omnibox_view_->HandleMousePressEvent(event); | |
oshima
2012/05/16 21:28:31
Is there reason why you should/want to ignore the
Daniel Erat
2012/05/16 22:03:10
It doesn't provide a result anymore; I don't think
| |
92 return result; | |
93 } | |
94 | |
95 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE { | |
96 bool result = views::Textfield::OnMouseDragged(event); | |
97 omnibox_view_->HandleMouseDragEvent(event); | |
98 return result; | |
99 } | |
100 | |
101 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE { | |
102 views::Textfield::OnMouseReleased(event); | |
103 omnibox_view_->HandleMouseReleaseEvent(event); | |
91 } | 104 } |
92 | 105 |
93 private: | 106 private: |
94 OmniboxViewViews* omnibox_view_; | 107 OmniboxViewViews* omnibox_view_; |
95 | 108 |
96 DISALLOW_COPY_AND_ASSIGN(AutocompleteTextfield); | 109 DISALLOW_COPY_AND_ASSIGN(AutocompleteTextfield); |
97 }; | 110 }; |
98 | 111 |
99 // Stores omnibox state for each tab. | 112 // Stores omnibox state for each tab. |
100 struct ViewState { | 113 struct ViewState { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 LocationBarView* location_bar) | 186 LocationBarView* location_bar) |
174 : popup_window_mode_(popup_window_mode), | 187 : popup_window_mode_(popup_window_mode), |
175 model_(new AutocompleteEditModel(this, controller, profile)), | 188 model_(new AutocompleteEditModel(this, controller, profile)), |
176 controller_(controller), | 189 controller_(controller), |
177 toolbar_model_(toolbar_model), | 190 toolbar_model_(toolbar_model), |
178 command_updater_(command_updater), | 191 command_updater_(command_updater), |
179 security_level_(ToolbarModel::NONE), | 192 security_level_(ToolbarModel::NONE), |
180 ime_composing_before_change_(false), | 193 ime_composing_before_change_(false), |
181 delete_at_end_pressed_(false), | 194 delete_at_end_pressed_(false), |
182 location_bar_view_(location_bar), | 195 location_bar_view_(location_bar), |
183 ime_candidate_window_open_(false) { | 196 ime_candidate_window_open_(false), |
197 select_all_on_mouse_release_(false) { | |
184 } | 198 } |
185 | 199 |
186 OmniboxViewViews::~OmniboxViewViews() { | 200 OmniboxViewViews::~OmniboxViewViews() { |
187 #if defined(OS_CHROMEOS) | 201 #if defined(OS_CHROMEOS) |
188 chromeos::input_method::InputMethodManager::GetInstance()-> | 202 chromeos::input_method::InputMethodManager::GetInstance()-> |
189 RemoveCandidateWindowObserver(this); | 203 RemoveCandidateWindowObserver(this); |
190 #endif | 204 #endif |
191 | 205 |
192 // Explicitly teardown members which have a reference to us. Just to be safe | 206 // Explicitly teardown members which have a reference to us. Just to be safe |
193 // we want them to be destroyed before destroying any other internal state. | 207 // we want them to be destroyed before destroying any other internal state. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 // the control-key state is changed. | 312 // the control-key state is changed. |
299 if (event.key_code() == ui::VKEY_CONTROL) { | 313 if (event.key_code() == ui::VKEY_CONTROL) { |
300 // TODO(oshima): investigate if we need to support keyboard with two | 314 // TODO(oshima): investigate if we need to support keyboard with two |
301 // controls. | 315 // controls. |
302 model_->OnControlKeyChanged(false); | 316 model_->OnControlKeyChanged(false); |
303 return true; | 317 return true; |
304 } | 318 } |
305 return false; | 319 return false; |
306 } | 320 } |
307 | 321 |
308 bool OmniboxViewViews::HandleMousePressEvent(const views::MouseEvent& event) { | 322 void OmniboxViewViews::HandleMousePressEvent(const views::MouseEvent& event) { |
309 if (!textfield_->HasFocus() && !textfield_->HasSelection()) { | 323 if (event.IsOnlyLeftMouseButton() && |
Peter Kasting
2012/05/16 21:10:53
This check isn't right, because we want click-and-
oshima
2012/05/16 21:28:31
I confirmed this on mac and win. linux doesn't but
Daniel Erat
2012/05/16 22:03:10
Ah, didn't know about that. Updated.
I'm not sur
Peter Kasting
2012/05/16 22:11:34
Dragging with the right button should never select
| |
324 !textfield_->HasFocus() && | |
325 !textfield_->HasSelection()) { | |
326 select_all_on_mouse_release_ = true; | |
327 } | |
328 } | |
329 | |
330 void OmniboxViewViews::HandleMouseDragEvent(const views::MouseEvent& event) { | |
331 select_all_on_mouse_release_ = false; | |
332 } | |
333 | |
334 void OmniboxViewViews::HandleMouseReleaseEvent(const views::MouseEvent& event) { | |
335 if (event.IsOnlyLeftMouseButton() && select_all_on_mouse_release_) | |
310 textfield_->SelectAll(); | 336 textfield_->SelectAll(); |
311 textfield_->RequestFocus(); | 337 select_all_on_mouse_release_ = false; |
Daniel Erat
2012/05/16 21:06:02
I'm dropping the RequestFocus() call and returning
| |
312 return true; | |
313 } | |
314 | |
315 return false; | |
316 } | 338 } |
317 | 339 |
318 void OmniboxViewViews::HandleFocusIn() { | 340 void OmniboxViewViews::HandleFocusIn() { |
319 // TODO(oshima): Get control key state. | 341 // TODO(oshima): Get control key state. |
320 model_->OnSetFocus(false); | 342 model_->OnSetFocus(false); |
321 // Don't call controller_->OnSetFocus as this view has already | 343 // Don't call controller_->OnSetFocus as this view has already |
322 // acquired the focus. | 344 // acquired the focus. |
323 } | 345 } |
324 | 346 |
325 void OmniboxViewViews::HandleFocusOut() { | 347 void OmniboxViewViews::HandleFocusOut() { |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, | 890 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, |
869 toolbar_model, | 891 toolbar_model, |
870 profile, | 892 profile, |
871 command_updater, | 893 command_updater, |
872 popup_window_mode, | 894 popup_window_mode, |
873 location_bar); | 895 location_bar); |
874 omnibox_view->Init(); | 896 omnibox_view->Init(); |
875 return omnibox_view; | 897 return omnibox_view; |
876 } | 898 } |
877 #endif | 899 #endif |
OLD | NEW |