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

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: Fix final nits 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
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view.h ('k') | chrome/browser/ui/views/frame/browser_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
80 if (!match.destination_url.is_valid())
81 return;
82 if (model_.get())
83 model_->OpenMatch(match, disposition, alternate_nav_url, selected_line);
84 }
85
86 bool OmniboxView::IsEditingOrEmpty() const {
87 return (model_.get() && model_->user_input_in_progress()) ||
88 (GetOmniboxTextLength() == 0);
89 }
90
91 int OmniboxView::GetIcon() const {
92 if (IsEditingOrEmpty()) {
93 return AutocompleteMatch::TypeToIcon(model_.get() ?
94 model_->CurrentTextType() : AutocompleteMatch::URL_WHAT_YOU_TYPED);
95 } else {
96 return toolbar_model_->GetIcon();
97 }
98 }
99
100 void OmniboxView::SetUserText(const string16& text) {
101 SetUserText(text, text, true);
102 }
103
104 void OmniboxView::SetUserText(const string16& text,
105 const string16& display_text,
106 bool update_popup) {
107 if (model_.get())
108 model_->SetUserText(text);
109 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup,
110 true);
111 }
112
113 void OmniboxView::RevertAll() {
114 CloseOmniboxPopup();
115 if (model_.get())
116 model_->Revert();
117 TextChanged();
118 }
119
120 void OmniboxView::CloseOmniboxPopup() {
121 if (model_.get())
122 model_->StopAutocomplete();
123 }
124
125 OmniboxView::OmniboxView(Profile* profile,
126 OmniboxEditController* controller,
127 ToolbarModel* toolbar_model,
128 CommandUpdater* command_updater)
129 : controller_(controller),
130 toolbar_model_(toolbar_model),
131 command_updater_(command_updater) {
132 // |profile| can be NULL in tests.
133 if (profile)
134 model_.reset(new OmniboxEditModel(this, controller, profile));
135 }
136
137 void OmniboxView::TextChanged() {
138 EmphasizeURLComponents();
139 if (model_.get())
140 model_->OnChanged();
141 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view.h ('k') | chrome/browser/ui/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698