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 // This file defines helper functions shared by the various implementations | 5 // This file defines helper functions shared by the various implementations |
6 // of OmniboxView. | 6 // of OmniboxView. |
7 | 7 |
8 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 8 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "ui/base/clipboard/clipboard.h" | 14 #include "ui/base/clipboard/clipboard.h" |
15 | 15 |
16 // static | |
16 string16 OmniboxView::StripJavascriptSchemas(const string16& text) { | 17 string16 OmniboxView::StripJavascriptSchemas(const string16& text) { |
17 const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) + | 18 const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) + |
18 ASCIIToUTF16(":")); | 19 ASCIIToUTF16(":")); |
19 string16 out(text); | 20 string16 out(text); |
20 while (StartsWith(out, kJsPrefix, false)) | 21 while (StartsWith(out, kJsPrefix, false)) |
21 TrimWhitespace(out.substr(kJsPrefix.length()), TRIM_LEADING, &out); | 22 TrimWhitespace(out.substr(kJsPrefix.length()), TRIM_LEADING, &out); |
22 return out; | 23 return out; |
23 } | 24 } |
24 | 25 |
25 // static | 26 // static |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 std::string url_str; | 60 std::string url_str; |
60 clipboard->ReadBookmark(NULL, &url_str); | 61 clipboard->ReadBookmark(NULL, &url_str); |
61 // pass resulting url string through GURL to normalize | 62 // pass resulting url string through GURL to normalize |
62 GURL url(url_str); | 63 GURL url(url_str); |
63 if (url.is_valid()) | 64 if (url.is_valid()) |
64 return StripJavascriptSchemas(UTF8ToUTF16(url.spec())); | 65 return StripJavascriptSchemas(UTF8ToUTF16(url.spec())); |
65 } | 66 } |
66 | 67 |
67 return string16(); | 68 return string16(); |
68 } | 69 } |
70 | |
71 OmniboxView::~OmniboxView() { | |
72 // Explicitly tear down objects with references to this. | |
73 model_.reset(); | |
74 } | |
75 | |
76 void OmniboxView::OpenMatch(const AutocompleteMatch& match, | |
77 WindowOpenDisposition disposition, | |
78 const GURL& alternate_nav_url, | |
79 size_t selected_line) { | |
80 // TODO(shess): Why is the caller passing an invalid url in the | |
81 // first place? Make sure that case isn't being dropped on the | |
82 // floor. | |
83 if (!match.destination_url.is_valid()) { | |
84 CHECK(false); | |
Peter Kasting
2012/07/26 23:03:24
Nit: Don't handle checkfailures -- if this really
dominich
2012/07/27 20:33:54
Confirmed that we don't get a hit here when typing
| |
85 return; | |
86 } | |
87 | |
88 model_->OpenMatch(match, disposition, alternate_nav_url, selected_line); | |
89 } | |
90 | |
91 bool OmniboxView::IsEditingOrEmpty() const { | |
92 return model_->user_input_in_progress() || (GetOmniboxTextLength() == 0); | |
93 } | |
94 | |
95 int OmniboxView::GetIcon() const { | |
96 return IsEditingOrEmpty() ? | |
97 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : | |
98 toolbar_model_->GetIcon(); | |
99 } | |
100 | |
101 void OmniboxView::SetUserText(const string16& text) { | |
102 SetUserText(text, text, true); | |
103 } | |
104 | |
105 void OmniboxView::SetUserText(const string16& text, | |
106 const string16& display_text, | |
107 bool update_popup) { | |
108 model_->SetUserText(text); | |
109 // TODO(deanm): something about selection / focus change here. | |
110 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, | |
111 true); | |
112 } | |
113 | |
114 void OmniboxView::RevertAll() { | |
115 ClosePopup(); | |
116 model_->Revert(); | |
117 TextChanged(); | |
118 } | |
119 | |
120 void OmniboxView::ClosePopup() { | |
121 model_->StopAutocomplete(); | |
122 } | |
123 | |
124 OmniboxView::OmniboxView(Profile* profile, | |
125 OmniboxEditController* controller, | |
126 ToolbarModel* toolbar_model, | |
127 CommandUpdater* command_updater) | |
128 : controller_(controller), | |
129 toolbar_model_(toolbar_model), | |
130 command_updater_(command_updater) { | |
131 // |profile| can be NULL in tests. | |
132 if (profile) | |
133 model_.reset(new OmniboxEditModel(this, controller, profile)); | |
134 } | |
135 | |
136 void OmniboxView::TextChanged() { | |
137 EmphasizeURLComponents(); | |
138 model_->OnChanged(); | |
139 } | |
OLD | NEW |