| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 11 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 13 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 14 #include "chrome/browser/command_updater.h" | 14 #include "chrome/browser/command_updater.h" |
| 15 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" |
| 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 20 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
| 21 #include "third_party/skia/include/core/SkColor.h" | 22 #include "third_party/skia/include/core/SkColor.h" |
| 22 #include "ui/base/accessibility/accessible_view_state.h" | 23 #include "ui/base/accessibility/accessible_view_state.h" |
| 23 #include "ui/base/dragdrop/drag_drop_types.h" | 24 #include "ui/base/dragdrop/drag_drop_types.h" |
| 24 #include "ui/base/ime/text_input_type.h" | 25 #include "ui/base/ime/text_input_type.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/font.h" | 28 #include "ui/gfx/font.h" |
| 28 #include "ui/gfx/render_text.h" | 29 #include "ui/gfx/render_text.h" |
| 29 #include "ui/views/events/event.h" | 30 #include "ui/views/events/event.h" |
| 30 #include "ui/views/layout/fill_layout.h" | 31 #include "ui/views/layout/fill_layout.h" |
| 31 #include "views/border.h" | 32 #include "views/border.h" |
| 32 #include "views/controls/textfield/textfield.h" | 33 #include "views/controls/textfield/textfield.h" |
| 33 | 34 |
| 34 #if defined(TOUCH_UI) | |
| 35 #include "chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents
_view.h" | |
| 36 #else | |
| 37 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" | |
| 38 #endif | |
| 39 | |
| 40 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 41 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" | 36 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| 42 #endif | 37 #endif |
| 43 | 38 |
| 44 namespace { | 39 namespace { |
| 45 | 40 |
| 46 // Textfield for autocomplete that intercepts events that are necessary | 41 // Textfield for autocomplete that intercepts events that are necessary |
| 47 // for OmniboxViewViews. | 42 // for OmniboxViewViews. |
| 48 class AutocompleteTextfield : public views::Textfield { | 43 class AutocompleteTextfield : public views::Textfield { |
| 49 public: | 44 public: |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // OmniboxViewViews public: | 174 // OmniboxViewViews public: |
| 180 | 175 |
| 181 void OmniboxViewViews::Init() { | 176 void OmniboxViewViews::Init() { |
| 182 // The height of the text view is going to change based on the font used. We | 177 // The height of the text view is going to change based on the font used. We |
| 183 // don't want to stretch the height, and we want it vertically centered. | 178 // don't want to stretch the height, and we want it vertically centered. |
| 184 // TODO(oshima): make sure the above happens with views. | 179 // TODO(oshima): make sure the above happens with views. |
| 185 textfield_ = new AutocompleteTextfield(this); | 180 textfield_ = new AutocompleteTextfield(this); |
| 186 textfield_->SetController(this); | 181 textfield_->SetController(this); |
| 187 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 182 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
| 188 | 183 |
| 189 #if defined(TOUCH_UI) | |
| 190 textfield_->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | |
| 191 ResourceBundle::LargeFont)); | |
| 192 #endif | |
| 193 | |
| 194 if (popup_window_mode_) | 184 if (popup_window_mode_) |
| 195 textfield_->SetReadOnly(true); | 185 textfield_->SetReadOnly(true); |
| 196 | 186 |
| 197 // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe | 187 // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe |
| 198 // themes. | 188 // themes. |
| 199 SetBaseColor(); | 189 SetBaseColor(); |
| 200 } | 190 } |
| 201 | 191 |
| 202 void OmniboxViewViews::SetBaseColor() { | 192 void OmniboxViewViews::SetBaseColor() { |
| 203 // TODO(oshima): Implement style change. | 193 // TODO(oshima): Implement style change. |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 textfield_->SelectRange(range); | 714 textfield_->SelectRange(range); |
| 725 } | 715 } |
| 726 | 716 |
| 727 string16 OmniboxViewViews::GetSelectedText() const { | 717 string16 OmniboxViewViews::GetSelectedText() const { |
| 728 // TODO(oshima): Support instant, IME. | 718 // TODO(oshima): Support instant, IME. |
| 729 return textfield_->GetSelectedText(); | 719 return textfield_->GetSelectedText(); |
| 730 } | 720 } |
| 731 | 721 |
| 732 AutocompletePopupView* OmniboxViewViews::CreatePopupView( | 722 AutocompletePopupView* OmniboxViewViews::CreatePopupView( |
| 733 View* location_bar) { | 723 View* location_bar) { |
| 734 #if defined(TOUCH_UI) | |
| 735 typedef TouchAutocompletePopupContentsView AutocompleteContentsView; | |
| 736 #else | |
| 737 typedef AutocompletePopupContentsView AutocompleteContentsView; | 724 typedef AutocompletePopupContentsView AutocompleteContentsView; |
| 738 #endif | |
| 739 return new AutocompleteContentsView(gfx::Font(), this, model_.get(), | 725 return new AutocompleteContentsView(gfx::Font(), this, model_.get(), |
| 740 location_bar); | 726 location_bar); |
| 741 } | 727 } |
| 742 | 728 |
| 743 #if defined(USE_AURA) | 729 #if defined(USE_AURA) |
| 744 // static | 730 // static |
| 745 OmniboxView* OmniboxView::CreateOmniboxView( | 731 OmniboxView* OmniboxView::CreateOmniboxView( |
| 746 AutocompleteEditController* controller, | 732 AutocompleteEditController* controller, |
| 747 ToolbarModel* toolbar_model, | 733 ToolbarModel* toolbar_model, |
| 748 Profile* profile, | 734 Profile* profile, |
| 749 CommandUpdater* command_updater, | 735 CommandUpdater* command_updater, |
| 750 bool popup_window_mode, | 736 bool popup_window_mode, |
| 751 LocationBarView* location_bar) { | 737 LocationBarView* location_bar) { |
| 752 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, | 738 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, |
| 753 toolbar_model, | 739 toolbar_model, |
| 754 profile, | 740 profile, |
| 755 command_updater, | 741 command_updater, |
| 756 popup_window_mode, | 742 popup_window_mode, |
| 757 location_bar); | 743 location_bar); |
| 758 omnibox_view->Init(); | 744 omnibox_view->Init(); |
| 759 return omnibox_view; | 745 return omnibox_view; |
| 760 } | 746 } |
| 761 #endif | 747 #endif |
| OLD | NEW |