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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 bool result = views::Textfield::OnMouseDragged(event); | 187 bool result = views::Textfield::OnMouseDragged(event); |
188 omnibox_view_->HandleMouseDragEvent(event); | 188 omnibox_view_->HandleMouseDragEvent(event); |
189 return result; | 189 return result; |
190 } | 190 } |
191 | 191 |
192 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE { | 192 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE { |
193 views::Textfield::OnMouseReleased(event); | 193 views::Textfield::OnMouseReleased(event); |
194 omnibox_view_->HandleMouseReleaseEvent(event); | 194 omnibox_view_->HandleMouseReleaseEvent(event); |
195 } | 195 } |
196 | 196 |
197 protected: | |
198 // views::View implementation. | |
199 virtual void PaintChildren(gfx::Canvas* canvas) { | |
200 views::Textfield::PaintChildren(canvas); | |
201 } | |
202 | |
203 private: | 197 private: |
204 OmniboxViewViews* omnibox_view_; | 198 OmniboxViewViews* omnibox_view_; |
205 LocationBarView* location_bar_view_; | 199 LocationBarView* location_bar_view_; |
206 | 200 |
207 DISALLOW_COPY_AND_ASSIGN(AutocompleteTextfield); | 201 DISALLOW_COPY_AND_ASSIGN(AutocompleteTextfield); |
208 }; | 202 }; |
209 | 203 |
210 // static | 204 // static |
211 const char OmniboxViewViews::kViewClassName[] = "BrowserOmniboxViewViews"; | 205 const char OmniboxViewViews::kViewClassName[] = "BrowserOmniboxViewViews"; |
212 | 206 |
213 OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, | 207 OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, |
214 ToolbarModel* toolbar_model, | 208 ToolbarModel* toolbar_model, |
215 Profile* profile, | 209 Profile* profile, |
216 CommandUpdater* command_updater, | 210 CommandUpdater* command_updater, |
217 bool popup_window_mode, | 211 bool popup_window_mode, |
218 LocationBarView* location_bar) | 212 LocationBarView* location_bar) |
219 : OmniboxView(profile, controller, toolbar_model, command_updater), | 213 : OmniboxView(profile, controller, toolbar_model, command_updater), |
220 textfield_(NULL), | 214 textfield_(NULL), |
221 popup_window_mode_(popup_window_mode), | 215 popup_window_mode_(popup_window_mode), |
222 security_level_(ToolbarModel::NONE), | 216 security_level_(ToolbarModel::NONE), |
223 ime_composing_before_change_(false), | 217 ime_composing_before_change_(false), |
224 delete_at_end_pressed_(false), | 218 delete_at_end_pressed_(false), |
225 location_bar_view_(location_bar), | 219 location_bar_view_(location_bar), |
226 ime_candidate_window_open_(false), | 220 ime_candidate_window_open_(false), |
227 select_all_on_mouse_release_(false), | 221 select_all_on_mouse_release_(false) { |
228 visible_caret_color_(SK_ColorBLACK) { | |
229 } | 222 } |
230 | 223 |
231 OmniboxViewViews::~OmniboxViewViews() { | 224 OmniboxViewViews::~OmniboxViewViews() { |
232 #if defined(OS_CHROMEOS) | 225 #if defined(OS_CHROMEOS) |
233 chromeos::input_method::InputMethodManager::GetInstance()-> | 226 chromeos::input_method::InputMethodManager::GetInstance()-> |
234 RemoveCandidateWindowObserver(this); | 227 RemoveCandidateWindowObserver(this); |
235 #endif | 228 #endif |
236 | 229 |
237 // Explicitly teardown members which have a reference to us. Just to be safe | 230 // Explicitly teardown members which have a reference to us. Just to be safe |
238 // we want them to be destroyed before destroying any other internal state. | 231 // we want them to be destroyed before destroying any other internal state. |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 // because if we already have invisible focus, the RequestFocus() call below | 576 // because if we already have invisible focus, the RequestFocus() call below |
584 // will short-circuit, preventing us from reaching | 577 // will short-circuit, preventing us from reaching |
585 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when we | 578 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when we |
586 // didn't previously have focus. | 579 // didn't previously have focus. |
587 model()->SetCaretVisibility(true); | 580 model()->SetCaretVisibility(true); |
588 // In views-implementation, the focus is on textfield rather than OmniboxView. | 581 // In views-implementation, the focus is on textfield rather than OmniboxView. |
589 textfield_->RequestFocus(); | 582 textfield_->RequestFocus(); |
590 } | 583 } |
591 | 584 |
592 void OmniboxViewViews::ApplyCaretVisibility() { | 585 void OmniboxViewViews::ApplyCaretVisibility() { |
593 if (textfield_->cursor_color() != textfield_->background_color()) | 586 textfield_->SetCursorEnabled(model()->is_caret_visible()); |
594 visible_caret_color_ = textfield_->cursor_color(); | |
595 // Setting the color of the text cursor (caret) to the background color | |
596 // effectively hides it. | |
597 textfield_->SetCursorColor(model()->is_caret_visible() ? | |
598 visible_caret_color_ : textfield_->background_color()); | |
599 } | 587 } |
600 | 588 |
601 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 589 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
602 const string16& display_text, | 590 const string16& display_text, |
603 bool save_original_selection) { | 591 bool save_original_selection) { |
604 if (save_original_selection) | 592 if (save_original_selection) |
605 textfield_->GetSelectedRange(&saved_temporary_selection_); | 593 textfield_->GetSelectedRange(&saved_temporary_selection_); |
606 | 594 |
607 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); | 595 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
608 } | 596 } |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 if (!text.empty()) { | 963 if (!text.empty()) { |
976 // Record this paste, so we can do different behavior. | 964 // Record this paste, so we can do different behavior. |
977 model()->on_paste(); | 965 model()->on_paste(); |
978 // Force a Paste operation to trigger the text_changed code in | 966 // Force a Paste operation to trigger the text_changed code in |
979 // OnAfterPossibleChange(), even if identical contents are pasted into the | 967 // OnAfterPossibleChange(), even if identical contents are pasted into the |
980 // text box. | 968 // text box. |
981 text_before_change_.clear(); | 969 text_before_change_.clear(); |
982 textfield_->ReplaceSelection(text); | 970 textfield_->ReplaceSelection(text); |
983 } | 971 } |
984 } | 972 } |
OLD | NEW |