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

Side by Side Diff: chrome/browser/cocoa/location_bar/location_bar_view_mac.mm

Issue 3624001: Implement Instant on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" 5 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/nsimage_cache_mac.h" 9 #include "base/nsimage_cache_mac.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/app/chrome_dll_resource.h" 14 #include "chrome/app/chrome_dll_resource.h"
15 #include "chrome/browser/alternate_nav_url_fetcher.h" 15 #include "chrome/browser/alternate_nav_url_fetcher.h"
16 #import "chrome/browser/app_controller_mac.h" 16 #import "chrome/browser/app_controller_mac.h"
17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
18 #import "chrome/browser/autocomplete/autocomplete_popup_model.h"
18 #include "chrome/browser/browser_list.h" 19 #include "chrome/browser/browser_list.h"
19 #import "chrome/browser/cocoa/content_setting_bubble_cocoa.h" 20 #import "chrome/browser/cocoa/content_setting_bubble_cocoa.h"
20 #include "chrome/browser/cocoa/event_utils.h" 21 #include "chrome/browser/cocoa/event_utils.h"
21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" 22 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h"
22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" 23 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h"
23 #import "chrome/browser/cocoa/first_run_bubble_controller.h" 24 #import "chrome/browser/cocoa/first_run_bubble_controller.h"
24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" 25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h"
25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" 26 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h"
26 #import "chrome/browser/cocoa/location_bar/content_setting_decoration.h" 27 #import "chrome/browser/cocoa/location_bar/content_setting_decoration.h"
27 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h" 28 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h"
28 #import "chrome/browser/cocoa/location_bar/keyword_hint_decoration.h" 29 #import "chrome/browser/cocoa/location_bar/keyword_hint_decoration.h"
29 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h" 30 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h"
30 #import "chrome/browser/cocoa/location_bar/page_action_decoration.h" 31 #import "chrome/browser/cocoa/location_bar/page_action_decoration.h"
31 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h" 32 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h"
32 #import "chrome/browser/cocoa/location_bar/star_decoration.h" 33 #import "chrome/browser/cocoa/location_bar/star_decoration.h"
33 #include "chrome/browser/command_updater.h" 34 #include "chrome/browser/command_updater.h"
34 #include "chrome/browser/content_setting_image_model.h" 35 #include "chrome/browser/content_setting_image_model.h"
35 #include "chrome/browser/content_setting_bubble_model.h" 36 #include "chrome/browser/content_setting_bubble_model.h"
36 #include "chrome/browser/defaults.h" 37 #include "chrome/browser/defaults.h"
37 #include "chrome/browser/extensions/extension_browser_event_router.h" 38 #include "chrome/browser/extensions/extension_browser_event_router.h"
38 #include "chrome/browser/extensions/extensions_service.h" 39 #include "chrome/browser/extensions/extensions_service.h"
39 #include "chrome/browser/extensions/extension_tabs_module.h" 40 #include "chrome/browser/extensions/extension_tabs_module.h"
41 #include "chrome/browser/instant/instant_controller.h"
40 #include "chrome/browser/location_bar_util.h" 42 #include "chrome/browser/location_bar_util.h"
41 #include "chrome/browser/profile.h" 43 #include "chrome/browser/profile.h"
42 #include "chrome/browser/search_engines/template_url.h" 44 #include "chrome/browser/search_engines/template_url.h"
43 #include "chrome/browser/search_engines/template_url_model.h" 45 #include "chrome/browser/search_engines/template_url_model.h"
44 #include "chrome/browser/tab_contents/navigation_entry.h" 46 #include "chrome/browser/tab_contents/navigation_entry.h"
45 #include "chrome/browser/tab_contents/tab_contents.h" 47 #include "chrome/browser/tab_contents/tab_contents.h"
46 #include "chrome/common/extensions/extension.h" 48 #include "chrome/common/extensions/extension.h"
47 #include "chrome/common/extensions/extension_action.h" 49 #include "chrome/common/extensions/extension_action.h"
48 #include "chrome/common/extensions/extension_resource.h" 50 #include "chrome/common/extensions/extension_resource.h"
49 #include "chrome/common/notification_service.h" 51 #include "chrome/common/notification_service.h"
(...skipping 25 matching lines...) Expand all
75 AutocompleteEditViewMac::GetFieldFont())), 77 AutocompleteEditViewMac::GetFieldFont())),
76 ev_bubble_decoration_( 78 ev_bubble_decoration_(
77 new EVBubbleDecoration(location_icon_decoration_.get(), 79 new EVBubbleDecoration(location_icon_decoration_.get(),
78 AutocompleteEditViewMac::GetFieldFont())), 80 AutocompleteEditViewMac::GetFieldFont())),
79 star_decoration_(new StarDecoration(command_updater)), 81 star_decoration_(new StarDecoration(command_updater)),
80 keyword_hint_decoration_( 82 keyword_hint_decoration_(
81 new KeywordHintDecoration(AutocompleteEditViewMac::GetFieldFont())), 83 new KeywordHintDecoration(AutocompleteEditViewMac::GetFieldFont())),
82 profile_(profile), 84 profile_(profile),
83 browser_(browser), 85 browser_(browser),
84 toolbar_model_(toolbar_model), 86 toolbar_model_(toolbar_model),
87 update_instant_(true),
85 transition_(PageTransition::TYPED), 88 transition_(PageTransition::TYPED),
86 first_run_bubble_(this) { 89 first_run_bubble_(this) {
87 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 90 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
88 DCHECK_EQ(i, content_setting_decorations_.size()); 91 DCHECK_EQ(i, content_setting_decorations_.size());
89 ContentSettingsType type = static_cast<ContentSettingsType>(i); 92 ContentSettingsType type = static_cast<ContentSettingsType>(i);
90 content_setting_decorations_.push_back( 93 content_setting_decorations_.push_back(
91 new ContentSettingDecoration(type, this, profile_)); 94 new ContentSettingDecoration(type, this, profile_));
92 } 95 }
93 96
94 registrar_.Add(this, 97 registrar_.Add(this,
(...skipping 23 matching lines...) Expand all
118 // of the left omnibox icon, so shift x and y co-ordinates. 121 // of the left omnibox icon, so shift x and y co-ordinates.
119 const NSPoint kOffset = NSMakePoint(1, 4); 122 const NSPoint kOffset = NSMakePoint(1, 4);
120 [FirstRunBubbleController showForView:field_ offset:kOffset profile:profile_]; 123 [FirstRunBubbleController showForView:field_ offset:kOffset profile:profile_];
121 } 124 }
122 125
123 std::wstring LocationBarViewMac::GetInputString() const { 126 std::wstring LocationBarViewMac::GetInputString() const {
124 return location_input_; 127 return location_input_;
125 } 128 }
126 129
127 void LocationBarViewMac::SetSuggestedText(const string16& text) { 130 void LocationBarViewMac::SetSuggestedText(const string16& text) {
128 // TODO: implement me. 131 // TODO(rohitrao): implement me. http://crbug.com/56385
129 NOTIMPLEMENTED();
130 } 132 }
131 133
132 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { 134 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const {
133 return disposition_; 135 return disposition_;
134 } 136 }
135 137
136 PageTransition::Type LocationBarViewMac::GetPageTransition() const { 138 PageTransition::Type LocationBarViewMac::GetPageTransition() const {
137 return transition_; 139 return transition_;
138 } 140 }
139 141
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); 196 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
195 star_decoration_->SetVisible(star_enabled); 197 star_decoration_->SetVisible(star_enabled);
196 RefreshPageActionDecorations(); 198 RefreshPageActionDecorations();
197 RefreshContentSettingsDecorations(); 199 RefreshContentSettingsDecorations();
198 // AutocompleteEditView restores state if the tab is non-NULL. 200 // AutocompleteEditView restores state if the tab is non-NULL.
199 edit_view_->Update(should_restore_state ? contents : NULL); 201 edit_view_->Update(should_restore_state ? contents : NULL);
200 OnChanged(); 202 OnChanged();
201 } 203 }
202 204
203 void LocationBarViewMac::OnAutocompleteWillClosePopup() { 205 void LocationBarViewMac::OnAutocompleteWillClosePopup() {
206 if (!update_instant_)
207 return;
208
209 InstantController* controller = browser_->instant();
210 if (controller && !controller->commit_on_mouse_up())
211 controller->DestroyPreviewContents();
204 } 212 }
205 213
206 void LocationBarViewMac::OnAutocompleteLosingFocus(gfx::NativeView unused) { 214 void LocationBarViewMac::OnAutocompleteLosingFocus(gfx::NativeView unused) {
215 InstantController* instant = browser_->instant();
216 if (!instant)
217 return;
218
219 if (!instant->is_active() || !instant->GetPreviewContents())
220 return;
221
222 // If |IsMouseDownFromActivate()| returns false, the RenderWidgetHostView did
223 // not receive a mouseDown event. Therefore, we should destroy the preview.
224 // Otherwise, the RWHV was clicked, so we commit the preview.
225 if (!instant->IsMouseDownFromActivate())
226 instant->DestroyPreviewContents();
227 else if (instant->IsShowingInstant())
228 instant->SetCommitOnMouseUp();
229 else
230 instant->CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST);
207 } 231 }
208 232
209 void LocationBarViewMac::OnAutocompleteWillAccept() { 233 void LocationBarViewMac::OnAutocompleteWillAccept() {
234 update_instant_ = false;
210 } 235 }
211 236
212 bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) { 237 bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) {
213 return false; 238 return false;
214 } 239 }
215 240
216 void LocationBarViewMac::OnPopupBoundsChanged(const gfx::Rect& bounds) { 241 void LocationBarViewMac::OnPopupBoundsChanged(const gfx::Rect& bounds) {
217 } 242 }
218 243
219 void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, 244 void LocationBarViewMac::OnAutocompleteAccept(const GURL& url,
220 WindowOpenDisposition disposition, 245 WindowOpenDisposition disposition,
221 PageTransition::Type transition, 246 PageTransition::Type transition,
222 const GURL& alternate_nav_url) { 247 const GURL& alternate_nav_url) {
223 if (!url.is_valid()) 248 // WARNING: don't add an early return here. The calls after the if must
224 return; 249 // happen.
250 if (url.is_valid()) {
251 location_input_ = UTF8ToWide(url.spec());
252 disposition_ = disposition;
253 transition_ = transition;
225 254
226 location_input_ = UTF8ToWide(url.spec()); 255 if (command_updater_) {
227 disposition_ = disposition; 256 if (!alternate_nav_url.is_valid()) {
228 transition_ = transition; 257 command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
229 258 } else {
230 if (!command_updater_) 259 AlternateNavURLFetcher* fetcher =
231 return; 260 new AlternateNavURLFetcher(alternate_nav_url);
232 261 // The AlternateNavURLFetcher will listen for the pending navigation
233 if (!alternate_nav_url.is_valid()) { 262 // notification that will be issued as a result of the "open URL." It
234 command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); 263 // will automatically install itself into that navigation controller.
235 return; 264 command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
265 if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
266 // I'm not sure this should be reachable, but I'm not also sure enough
267 // that it shouldn't to stick in a NOTREACHED(). In any case, this is
268 // harmless.
269 delete fetcher;
270 } else {
271 // The navigation controller will delete the fetcher.
272 }
273 }
274 }
236 } 275 }
237 276
238 AlternateNavURLFetcher* fetcher = 277 if (browser_->instant())
239 new AlternateNavURLFetcher(alternate_nav_url); 278 browser_->instant()->DestroyPreviewContents();
240 // The AlternateNavURLFetcher will listen for the pending navigation 279
241 // notification that will be issued as a result of the "open URL." It 280 update_instant_ = true;
242 // will automatically install itself into that navigation controller.
243 command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
244 if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
245 // I'm not sure this should be reachable, but I'm not also sure enough
246 // that it shouldn't to stick in a NOTREACHED(). In any case, this is
247 // harmless.
248 delete fetcher;
249 } else {
250 // The navigation controller will delete the fetcher.
251 }
252 } 281 }
253 282
254 void LocationBarViewMac::OnChanged() { 283 void LocationBarViewMac::OnChanged() {
255 // Update the location-bar icon. 284 // Update the location-bar icon.
256 const int resource_id = edit_view_->GetIcon(); 285 const int resource_id = edit_view_->GetIcon();
257 NSImage* image = AutocompleteEditViewMac::ImageForResource(resource_id); 286 NSImage* image = AutocompleteEditViewMac::ImageForResource(resource_id);
258 location_icon_decoration_->SetImage(image); 287 location_icon_decoration_->SetImage(image);
259 ev_bubble_decoration_->SetImage(image); 288 ev_bubble_decoration_->SetImage(image);
260 Layout(); 289 Layout();
290
291 InstantController* instant = browser_->instant();
292 string16 suggested_text;
293 if (update_instant_ && instant && GetTabContents()) {
294 if (edit_view_->model()->user_input_in_progress() &&
295 edit_view_->model()->popup_model()->IsOpen()) {
296 instant->Update(GetTabContents(),
297 edit_view_->model()->CurrentMatch(),
298 WideToUTF16(edit_view_->GetText()),
299 &suggested_text);
300 } else {
301 if (instant->is_active())
302 instant->DestroyPreviewContents();
303 }
304 }
261 } 305 }
262 306
263 void LocationBarViewMac::OnInputInProgress(bool in_progress) { 307 void LocationBarViewMac::OnInputInProgress(bool in_progress) {
264 toolbar_model_->set_input_in_progress(in_progress); 308 toolbar_model_->set_input_in_progress(in_progress);
265 Update(NULL, false); 309 Update(NULL, false);
266 } 310 }
267 311
268 void LocationBarViewMac::OnSetFocus() { 312 void LocationBarViewMac::OnSetFocus() {
269 // Update the keyword and search hint states. 313 // Update the keyword and search hint states.
270 OnChanged(); 314 OnChanged();
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 637
594 // These need to change anytime the layout changes. 638 // These need to change anytime the layout changes.
595 // TODO(shess): Anytime the field editor might have changed, the 639 // TODO(shess): Anytime the field editor might have changed, the
596 // cursor rects almost certainly should have changed. The tooltips 640 // cursor rects almost certainly should have changed. The tooltips
597 // might change even when the rects don't change. 641 // might change even when the rects don't change.
598 [field_ resetFieldEditorFrameIfNeeded]; 642 [field_ resetFieldEditorFrameIfNeeded];
599 [field_ updateCursorAndToolTipRects]; 643 [field_ updateCursorAndToolTipRects];
600 644
601 [field_ setNeedsDisplay:YES]; 645 [field_ setNeedsDisplay:YES];
602 } 646 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/location_bar/location_bar_view_mac.h ('k') | chrome/browser/cocoa/previewable_contents_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698