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 OmniboxEditModel* OmniboxView::GetModel() { | |
17 return model_.get(); | |
18 } | |
19 | |
20 const OmniboxEditModel* OmniboxView::GetModel() const { | |
21 return model_.get(); | |
22 } | |
23 | |
24 CommandUpdater* OmniboxView::GetCommandUpdater() { | |
25 return command_updater_; | |
26 } | |
27 | |
28 const CommandUpdater* OmniboxView::GetCommandUpdater() const { | |
29 return command_updater_; | |
30 } | |
31 | |
32 // static | |
16 string16 OmniboxView::StripJavascriptSchemas(const string16& text) { | 33 string16 OmniboxView::StripJavascriptSchemas(const string16& text) { |
17 const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) + | 34 const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) + |
18 ASCIIToUTF16(":")); | 35 ASCIIToUTF16(":")); |
19 string16 out(text); | 36 string16 out(text); |
20 while (StartsWith(out, kJsPrefix, false)) | 37 while (StartsWith(out, kJsPrefix, false)) |
21 TrimWhitespace(out.substr(kJsPrefix.length()), TRIM_LEADING, &out); | 38 TrimWhitespace(out.substr(kJsPrefix.length()), TRIM_LEADING, &out); |
22 return out; | 39 return out; |
23 } | 40 } |
24 | 41 |
25 // static | 42 // static |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 std::string url_str; | 76 std::string url_str; |
60 clipboard->ReadBookmark(NULL, &url_str); | 77 clipboard->ReadBookmark(NULL, &url_str); |
61 // pass resulting url string through GURL to normalize | 78 // pass resulting url string through GURL to normalize |
62 GURL url(url_str); | 79 GURL url(url_str); |
63 if (url.is_valid()) | 80 if (url.is_valid()) |
64 return StripJavascriptSchemas(UTF8ToUTF16(url.spec())); | 81 return StripJavascriptSchemas(UTF8ToUTF16(url.spec())); |
65 } | 82 } |
66 | 83 |
67 return string16(); | 84 return string16(); |
68 } | 85 } |
86 | |
87 void OmniboxView::OpenMatch(const AutocompleteMatch& match, | |
88 WindowOpenDisposition disposition, | |
89 const GURL& alternate_nav_url, | |
90 size_t selected_line) { | |
91 // TODO(shess): Why is the caller passing an invalid url in the | |
92 // first place? Make sure that case isn't being dropped on the | |
93 // floor. | |
Peter Kasting
2012/07/26 03:59:17
I think this can perhaps happen if for example you
| |
94 if (!match.destination_url.is_valid()) { | |
Peter Kasting
2012/07/26 03:59:17
Nit: No {}
dominich
2012/07/26 22:33:24
Done.
| |
95 return; | |
96 } | |
97 | |
98 model_->OpenMatch(match, disposition, alternate_nav_url, selected_line); | |
99 } | |
100 | |
101 bool OmniboxView::IsEditingOrEmpty() const { | |
102 return model_->user_input_in_progress() || (GetOmniboxTextLength() == 0); | |
103 } | |
104 | |
105 int OmniboxView::GetIcon() const { | |
106 return IsEditingOrEmpty() ? | |
107 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : | |
108 toolbar_model_->GetIcon(); | |
109 } | |
110 | |
111 void OmniboxView::SetUserText(const string16& text) { | |
112 SetUserText(text, text, true); | |
113 } | |
114 | |
115 void OmniboxView::SetUserText(const string16& text, | |
116 const string16& display_text, | |
117 bool update_popup) { | |
118 model_->SetUserText(text); | |
119 // TODO(deanm): something about selection / focus change here. | |
Peter Kasting
2012/07/26 03:59:17
I don't know what this comment means, and I'm incl
Peter Kasting
2012/07/26 23:03:24
Note this is still outstanding.
dominich
2012/07/30 16:42:59
I'm tempted to just nuke it. We don't have any ope
| |
120 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, | |
121 true); | |
122 } | |
123 | |
124 void OmniboxView::RevertAll() { | |
125 ClosePopup(); | |
126 model_->Revert(); | |
127 TextChanged(); | |
128 } | |
129 | |
130 void OmniboxView::ClosePopup() { | |
131 model_->StopAutocomplete(); | |
132 } | |
133 | |
134 OmniboxView::~OmniboxView() { | |
135 } | |
136 | |
137 OmniboxView::OmniboxView(Profile* profile, | |
138 OmniboxEditController* controller, | |
139 ToolbarModel* toolbar_model, | |
140 CommandUpdater* command_updater) | |
141 : controller_(controller), | |
142 toolbar_model_(toolbar_model), | |
143 command_updater_(command_updater) { | |
144 // |profile| can be NULL in tests. | |
145 if (profile) | |
146 model_.reset(new OmniboxEditModel(this, controller, profile)); | |
147 } | |
148 | |
149 void OmniboxView::TextChanged() { | |
150 EmphasizeURLComponents(); | |
151 model_->OnChanged(); | |
152 } | |
OLD | NEW |