Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_view.cc

Issue 10810062: Moving common code into OmniboxView from OmniboxView* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/autocomplete/autocomplete_match.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "ui/base/clipboard/clipboard.h" 15 #include "ui/base/clipboard/clipboard.h"
15 16
17 // static
16 string16 OmniboxView::StripJavascriptSchemas(const string16& text) { 18 string16 OmniboxView::StripJavascriptSchemas(const string16& text) {
17 const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) + 19 const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) +
18 ASCIIToUTF16(":")); 20 ASCIIToUTF16(":"));
19 string16 out(text); 21 string16 out(text);
20 while (StartsWith(out, kJsPrefix, false)) 22 while (StartsWith(out, kJsPrefix, false))
21 TrimWhitespace(out.substr(kJsPrefix.length()), TRIM_LEADING, &out); 23 TrimWhitespace(out.substr(kJsPrefix.length()), TRIM_LEADING, &out);
22 return out; 24 return out;
23 } 25 }
24 26
25 // static 27 // static
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 std::string url_str; 61 std::string url_str;
60 clipboard->ReadBookmark(NULL, &url_str); 62 clipboard->ReadBookmark(NULL, &url_str);
61 // pass resulting url string through GURL to normalize 63 // pass resulting url string through GURL to normalize
62 GURL url(url_str); 64 GURL url(url_str);
63 if (url.is_valid()) 65 if (url.is_valid())
64 return StripJavascriptSchemas(UTF8ToUTF16(url.spec())); 66 return StripJavascriptSchemas(UTF8ToUTF16(url.spec()));
65 } 67 }
66 68
67 return string16(); 69 return string16();
68 } 70 }
71
72 OmniboxView::~OmniboxView() {
73 }
74
75 void OmniboxView::OpenMatch(const AutocompleteMatch& match,
76 WindowOpenDisposition disposition,
77 const GURL& alternate_nav_url,
78 size_t selected_line) {
79 // Invalid URLs such as chrome://history can end up here.
Peter Kasting 2012/08/07 02:47:05 Oh? I thought this didn't happen? Did you find a
dominich 2012/08/07 17:48:20 Yes - typing chrome://history :)
80 if (!match.destination_url.is_valid())
81 return;
82 // |model_| can be NULL in tests.
Peter Kasting 2012/08/07 02:47:05 Nit: Instead of putting these comments in every fu
dominich 2012/08/07 17:48:20 Done.
83 if (model_.get())
84 model_->OpenMatch(match, disposition, alternate_nav_url, selected_line);
85 }
86
87 bool OmniboxView::IsEditingOrEmpty() const {
88 // |model_| can be NULL in tests.
89 return (model_.get() && model_->user_input_in_progress()) ||
90 (GetOmniboxTextLength() == 0);
91 }
92
93 int OmniboxView::GetIcon() const {
94 // |model_| can be NULL in tests.
95 return IsEditingOrEmpty() ?
Peter Kasting 2012/08/07 02:47:05 Nit: Don't nest ?:s
dominich 2012/08/07 17:48:20 Done.
96 AutocompleteMatch::TypeToIcon(model_.get() ?
97 model_->CurrentTextType() : AutocompleteMatch::URL_WHAT_YOU_TYPED) :
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_| can be NULL in tests.
109 if (model_.get())
110 model_->SetUserText(text);
111 // TODO(deanm): something about selection / focus change here.
Peter Kasting 2012/08/07 02:47:05 Nit: I thought you were going to kill this comment
dominich 2012/08/07 17:48:20 Done.
112 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup,
113 true);
114 }
115
116 void OmniboxView::RevertAll() {
117 CloseAutocompletePopup();
118 // |model_| can be NULL in tests.
119 if (model_.get())
120 model_->Revert();
121 TextChanged();
122 }
123
124 void OmniboxView::CloseAutocompletePopup() {
125 // |model_| can be NULL in tests.
126 if (model_.get())
127 model_->StopAutocomplete();
128 }
129
130 OmniboxView::OmniboxView(Profile* profile,
131 OmniboxEditController* controller,
132 ToolbarModel* toolbar_model,
133 CommandUpdater* command_updater)
134 : controller_(controller),
135 toolbar_model_(toolbar_model),
136 command_updater_(command_updater) {
137 // |profile| can be NULL in tests.
138 if (profile)
139 model_.reset(new OmniboxEditModel(this, controller, profile));
140 }
141
142 void OmniboxView::TextChanged() {
143 EmphasizeURLComponents();
144 // |model_| can be NULL in tests.
145 if (model_.get())
146 model_->OnChanged();
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698