| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/search/instant_page.h" | 5 #include "chrome/browser/ui/search/instant_page.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
| 9 #include "chrome/browser/ui/search/search_model.h" | 9 #include "chrome/browser/ui/search/search_model.h" |
| 10 #include "chrome/browser/ui/search/search_tab_helper.h" | 10 #include "chrome/browser/ui/search/search_tab_helper.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 bool verbatim) { | 47 bool verbatim) { |
| 48 Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim, | 48 Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim, |
| 49 selection_start, selection_end)); | 49 selection_start, selection_end)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void InstantPage::Submit(const string16& text) { | 52 void InstantPage::Submit(const string16& text) { |
| 53 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); | 53 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void InstantPage::Cancel(const string16& text) { | 56 void InstantPage::Cancel(const string16& text) { |
| 57 if (off_the_record_) |
| 58 return; |
| 59 |
| 57 Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text)); | 60 Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text)); |
| 58 } | 61 } |
| 59 | 62 |
| 60 void InstantPage::SetPopupBounds(const gfx::Rect& bounds) { | 63 void InstantPage::SetPopupBounds(const gfx::Rect& bounds) { |
| 64 if (off_the_record_) |
| 65 return; |
| 66 |
| 61 Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds)); | 67 Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds)); |
| 62 } | 68 } |
| 63 | 69 |
| 64 void InstantPage::SetOmniboxBounds(const gfx::Rect& bounds) { | 70 void InstantPage::SetOmniboxBounds(const gfx::Rect& bounds) { |
| 65 Send(new ChromeViewMsg_SearchBoxMarginChange( | 71 Send(new ChromeViewMsg_SearchBoxMarginChange( |
| 66 routing_id(), bounds.x(), bounds.width())); | 72 routing_id(), bounds.x(), bounds.width())); |
| 67 } | 73 } |
| 68 | 74 |
| 69 void InstantPage::InitializeFonts() { | 75 void InstantPage::InitializeFonts() { |
| 76 if (off_the_record_) |
| 77 return; |
| 78 |
| 70 #if defined(OS_MACOSX) | 79 #if defined(OS_MACOSX) |
| 71 // This value should be kept in sync with OmniboxViewMac::GetFieldFont. | 80 // This value should be kept in sync with OmniboxViewMac::GetFieldFont. |
| 72 const gfx::Font omnibox_font("Helvetica Neue", 16); | 81 const gfx::Font omnibox_font("Helvetica Neue", 16); |
| 73 #else | 82 #else |
| 74 const gfx::Font& omnibox_font = | 83 const gfx::Font& omnibox_font = |
| 75 ui::ResourceBundle::GetSharedInstance().GetFont( | 84 ui::ResourceBundle::GetSharedInstance().GetFont( |
| 76 ui::ResourceBundle::MediumFont); | 85 ui::ResourceBundle::MediumFont); |
| 77 #endif | 86 #endif |
| 78 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName()); | 87 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName()); |
| 79 size_t omnibox_font_size = omnibox_font.GetFontSize(); | 88 size_t omnibox_font_size = omnibox_font.GetFontSize(); |
| 80 Send(new ChromeViewMsg_SearchBoxFontInformation( | 89 Send(new ChromeViewMsg_SearchBoxFontInformation( |
| 81 routing_id(), omnibox_font_name, omnibox_font_size)); | 90 routing_id(), omnibox_font_name, omnibox_font_size)); |
| 82 } | 91 } |
| 83 | 92 |
| 84 void InstantPage::SendAutocompleteResults( | 93 void InstantPage::SendAutocompleteResults( |
| 85 const std::vector<InstantAutocompleteResult>& results) { | 94 const std::vector<InstantAutocompleteResult>& results) { |
| 95 if (off_the_record_) |
| 96 return; |
| 97 |
| 86 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); | 98 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); |
| 87 } | 99 } |
| 88 | 100 |
| 89 void InstantPage::UpOrDownKeyPressed(int count) { | 101 void InstantPage::UpOrDownKeyPressed(int count) { |
| 102 if (off_the_record_) |
| 103 return; |
| 104 |
| 90 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); | 105 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); |
| 91 } | 106 } |
| 92 | 107 |
| 93 void InstantPage::EscKeyPressed() { | 108 void InstantPage::EscKeyPressed() { |
| 109 if (off_the_record_) |
| 110 return; |
| 111 |
| 94 Send(new ChromeViewMsg_SearchBoxEscKeyPressed(routing_id())); | 112 Send(new ChromeViewMsg_SearchBoxEscKeyPressed(routing_id())); |
| 95 } | 113 } |
| 96 | 114 |
| 97 void InstantPage::CancelSelection(const string16& user_text, | 115 void InstantPage::CancelSelection(const string16& user_text, |
| 98 size_t selection_start, | 116 size_t selection_start, |
| 99 size_t selection_end, | 117 size_t selection_end, |
| 100 bool verbatim) { | 118 bool verbatim) { |
| 119 if (off_the_record_) |
| 120 return; |
| 121 |
| 101 Send(new ChromeViewMsg_SearchBoxCancelSelection( | 122 Send(new ChromeViewMsg_SearchBoxCancelSelection( |
| 102 routing_id(), user_text, verbatim, selection_start, selection_end)); | 123 routing_id(), user_text, verbatim, selection_start, selection_end)); |
| 103 } | 124 } |
| 104 | 125 |
| 105 void InstantPage::SendThemeBackgroundInfo( | 126 void InstantPage::SendThemeBackgroundInfo( |
| 106 const ThemeBackgroundInfo& theme_info) { | 127 const ThemeBackgroundInfo& theme_info) { |
| 128 if (off_the_record_) |
| 129 return; |
| 130 |
| 107 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info)); | 131 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info)); |
| 108 } | 132 } |
| 109 | 133 |
| 110 void InstantPage::SetDisplayInstantResults(bool display_instant_results) { | 134 void InstantPage::SetDisplayInstantResults(bool display_instant_results) { |
| 135 if (off_the_record_) |
| 136 return; |
| 137 |
| 111 Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults( | 138 Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults( |
| 112 routing_id(), display_instant_results)); | 139 routing_id(), display_instant_results)); |
| 113 } | 140 } |
| 114 | 141 |
| 115 void InstantPage::FocusChanged(OmniboxFocusState state, | 142 void InstantPage::FocusChanged(OmniboxFocusState state, |
| 116 OmniboxFocusChangeReason reason) { | 143 OmniboxFocusChangeReason reason) { |
| 144 if (off_the_record_) |
| 145 return; |
| 146 |
| 117 Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason)); | 147 Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason)); |
| 118 } | 148 } |
| 119 | 149 |
| 120 void InstantPage::SetInputInProgress(bool input_in_progress) { | 150 void InstantPage::SetInputInProgress(bool input_in_progress) { |
| 151 if (off_the_record_) |
| 152 return; |
| 153 |
| 121 Send(new ChromeViewMsg_SearchBoxSetInputInProgress( | 154 Send(new ChromeViewMsg_SearchBoxSetInputInProgress( |
| 122 routing_id(), input_in_progress)); | 155 routing_id(), input_in_progress)); |
| 123 } | 156 } |
| 124 | 157 |
| 125 void InstantPage::SendMostVisitedItems( | 158 void InstantPage::SendMostVisitedItems( |
| 126 const std::vector<InstantMostVisitedItem>& items) { | 159 const std::vector<InstantMostVisitedItem>& items) { |
| 160 if (off_the_record_) |
| 161 return; |
| 162 |
| 127 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items)); | 163 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items)); |
| 128 } | 164 } |
| 129 | 165 |
| 130 void InstantPage::ToggleVoiceSearch() { | 166 void InstantPage::ToggleVoiceSearch() { |
| 131 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id())); | 167 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id())); |
| 132 } | 168 } |
| 133 | 169 |
| 134 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url) | 170 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url, |
| 171 bool off_the_record) |
| 135 : delegate_(delegate), | 172 : delegate_(delegate), |
| 136 instant_url_(instant_url) { | 173 instant_url_(instant_url), |
| 174 off_the_record_(off_the_record) { |
| 137 } | 175 } |
| 138 | 176 |
| 139 void InstantPage::SetContents(content::WebContents* web_contents) { | 177 void InstantPage::SetContents(content::WebContents* web_contents) { |
| 140 ClearContents(); | 178 ClearContents(); |
| 141 | 179 |
| 142 if (!web_contents) | 180 if (!web_contents) |
| 143 return; | 181 return; |
| 144 | 182 |
| 145 Observe(web_contents); | 183 Observe(web_contents); |
| 146 SearchModel* model = SearchTabHelper::FromWebContents(contents())->model(); | 184 SearchModel* model = SearchTabHelper::FromWebContents(contents())->model(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 390 |
| 353 delegate_->UndoAllMostVisitedDeletions(); | 391 delegate_->UndoAllMostVisitedDeletions(); |
| 354 } | 392 } |
| 355 | 393 |
| 356 void InstantPage::ClearContents() { | 394 void InstantPage::ClearContents() { |
| 357 if (contents()) | 395 if (contents()) |
| 358 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); | 396 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); |
| 359 | 397 |
| 360 Observe(NULL); | 398 Observe(NULL); |
| 361 } | 399 } |
| OLD | NEW |