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/property_bag.h" | 8 #include "base/property_bag.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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 // Explicitly teardown members which have a reference to us. Just to be safe | 205 // Explicitly teardown members which have a reference to us. Just to be safe |
206 // we want them to be destroyed before destroying any other internal state. | 206 // we want them to be destroyed before destroying any other internal state. |
207 popup_view_.reset(); | 207 popup_view_.reset(); |
208 model_.reset(); | 208 model_.reset(); |
209 } | 209 } |
210 | 210 |
211 //////////////////////////////////////////////////////////////////////////////// | 211 //////////////////////////////////////////////////////////////////////////////// |
212 // OmniboxViewViews public: | 212 // OmniboxViewViews public: |
213 | 213 |
214 void OmniboxViewViews::Init() { | 214 void OmniboxViewViews::Init(views::View* popup_parent_view) { |
215 // The height of the text view is going to change based on the font used. We | 215 // The height of the text view is going to change based on the font used. We |
216 // don't want to stretch the height, and we want it vertically centered. | 216 // don't want to stretch the height, and we want it vertically centered. |
217 // TODO(oshima): make sure the above happens with views. | 217 // TODO(oshima): make sure the above happens with views. |
218 textfield_ = new AutocompleteTextfield(this); | 218 textfield_ = new AutocompleteTextfield(this); |
219 textfield_->SetController(this); | 219 textfield_->SetController(this); |
220 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 220 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
221 | 221 |
222 if (popup_window_mode_) | 222 if (popup_window_mode_) |
223 textfield_->SetReadOnly(true); | 223 textfield_->SetReadOnly(true); |
224 | 224 |
225 const int font_size = GetEditFontPixelSize(popup_window_mode_); | 225 const int font_size = GetEditFontPixelSize(popup_window_mode_); |
226 const int old_size = textfield_->font().GetFontSize(); | 226 const int old_size = textfield_->font().GetFontSize(); |
227 if (font_size != old_size) | 227 if (font_size != old_size) |
228 textfield_->SetFont(textfield_->font().DeriveFont(font_size - old_size)); | 228 textfield_->SetFont(textfield_->font().DeriveFont(font_size - old_size)); |
229 | 229 |
230 // Create popup view using the same font as |textfield_|'s. | 230 // Create popup view using the same font as |textfield_|'s. |
231 popup_view_.reset( | 231 popup_view_.reset( |
232 OmniboxPopupContentsView::CreateForEnvironment( | 232 OmniboxPopupContentsView::Create( |
233 textfield_->font(), this, model_.get(), location_bar_view_)); | 233 textfield_->font(), this, model_.get(), location_bar_view_, |
| 234 popup_parent_view)); |
234 | 235 |
235 const int vertical_margin = !popup_window_mode_ ? | 236 const int vertical_margin = !popup_window_mode_ ? |
236 kAutocompleteVerticalMargin : kAutocompleteVerticalMarginInPopup; | 237 kAutocompleteVerticalMargin : kAutocompleteVerticalMarginInPopup; |
237 set_border(views::Border::CreateEmptyBorder(vertical_margin, 0, | 238 set_border(views::Border::CreateEmptyBorder(vertical_margin, 0, |
238 vertical_margin, 0)); | 239 vertical_margin, 0)); |
239 #if defined(OS_CHROMEOS) | 240 #if defined(OS_CHROMEOS) |
240 chromeos::input_method::InputMethodManager::GetInstance()-> | 241 chromeos::input_method::InputMethodManager::GetInstance()-> |
241 AddCandidateWindowObserver(this); | 242 AddCandidateWindowObserver(this); |
242 #endif | 243 #endif |
243 } | 244 } |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 const ui::Range& range) { | 886 const ui::Range& range) { |
886 if (text != GetText()) | 887 if (text != GetText()) |
887 textfield_->SetText(text); | 888 textfield_->SetText(text); |
888 textfield_->SelectRange(range); | 889 textfield_->SelectRange(range); |
889 } | 890 } |
890 | 891 |
891 string16 OmniboxViewViews::GetSelectedText() const { | 892 string16 OmniboxViewViews::GetSelectedText() const { |
892 // TODO(oshima): Support instant, IME. | 893 // TODO(oshima): Support instant, IME. |
893 return textfield_->GetSelectedText(); | 894 return textfield_->GetSelectedText(); |
894 } | 895 } |
OLD | NEW |