diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 01:34:18 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 01:34:18 +0000 |
commit | 30179058aa633f1052869d75936a09dd8e7b9cf7 (patch) | |
tree | 72ef7f6f34bbdd0e8c3d5565ea3bac1f0aba0099 | |
parent | f8d60f4b509c4673d5e9558e822dca3de4183e99 (diff) | |
download | chromium_src-30179058aa633f1052869d75936a09dd8e7b9cf7.zip chromium_src-30179058aa633f1052869d75936a09dd8e7b9cf7.tar.gz chromium_src-30179058aa633f1052869d75936a09dd8e7b9cf7.tar.bz2 |
[Mac] Initial Instant implementation.
This is a very rough cut. Many things are still unfinished and will be fixed in future CLs:
- Clicking on instant results clears the results.
- Suggestions do not work yet.
- The omnibox popup overlaps with instant results.
- HTTP auth dialogs cause crashes.
BUG=56385
TEST=No visible impact when --enable-match-preview is not set on the command line.
TEST=Instant results should appear when typing in the omnibox.
TEST=Instant results should disappear when clicking outside the browser window or clicking on devtools or the sidebar.
Review URL: http://codereview.chromium.org/3624001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62221 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 115 insertions, 35 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index 0c2646e..46bab39 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -429,6 +429,9 @@ void AutocompleteEditViewMac::UpdatePopup() { } void AutocompleteEditViewMac::ClosePopup() { + if (popup_view_->GetModel()->IsOpen()) + controller_->OnAutocompleteWillClosePopup(); + popup_view_->GetModel()->StopAutocomplete(); } @@ -762,6 +765,7 @@ void AutocompleteEditViewMac::OnSetFocus(bool control_down) { void AutocompleteEditViewMac::OnKillFocus() { // Tell the model to reset itself. + controller_->OnAutocompleteLosingFocus(NULL); model_->OnKillFocus(); controller_->OnKillFocus(); } diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 45b7085..108a9269 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -565,13 +565,11 @@ void BrowserWindowCocoa::OpenTabpose() { } void BrowserWindowCocoa::ShowInstant(TabContents* preview_contents) { - // TODO: implement me - NOTIMPLEMENTED(); + [controller_ showInstant:preview_contents]; } void BrowserWindowCocoa::HideInstant() { - // TODO: implement me - NOTIMPLEMENTED(); + [controller_ hideInstant]; } gfx::Rect BrowserWindowCocoa::GetInstantBounds() { diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 2a580de..27264d7 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -261,6 +261,10 @@ class TabContents; // browser. - (void)toggleTabStripDisplayMode; +// Shows or hides the Instant preview contents. +- (void)showInstant:(TabContents*)previewContents; +- (void)hideInstant; + // Called when the Add Search Engine dialog is closed. - (void)sheetDidEnd:(NSWindow*)sheet returnCode:(NSInteger)code diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index f2fc066d..86f3b5e 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -1372,6 +1372,11 @@ } - (void)onReplaceTabWithContents:(TabContents*)contents { + // This is only called when instant results are committed. Simply remove the + // preview view; the tab strip controller will reinstall the view as the + // active view. + [previewableContentsController_ hidePreview]; + [self updateBookmarkBarVisibilityWithAnimation:NO]; } - (void)onSelectedTabChange:(TabStripModelObserver::TabChangeType)change { @@ -1718,6 +1723,21 @@ willAnimateFromState:(bookmarks::VisualState)oldState return browser_->tabstrip_model()->delegate()->UseVerticalTabs(); } +- (void)showInstant:(TabContents*)previewContents { + [previewableContentsController_ showPreview:previewContents]; + [self updateBookmarkBarVisibilityWithAnimation:NO]; +} + +- (void)hideInstant { + // TODO(rohitrao): Revisit whether or not this method should be called when + // instant isn't showing. + if (![previewableContentsController_ isShowingPreview]) + return; + + [previewableContentsController_ hidePreview]; + [self updateBookmarkBarVisibilityWithAnimation:NO]; +} + - (void)sheetDidEnd:(NSWindow*)sheet returnCode:(NSInteger)code context:(void*)context { diff --git a/chrome/browser/cocoa/browser_window_controller_private.mm b/chrome/browser/cocoa/browser_window_controller_private.mm index 819dbed..30132d47 100644 --- a/chrome/browser/cocoa/browser_window_controller_private.mm +++ b/chrome/browser/cocoa/browser_window_controller_private.mm @@ -450,7 +450,9 @@ willPositionSheet:(NSWindow*)sheet - (BOOL)shouldShowDetachedBookmarkBar { DCHECK(browser_.get()); TabContents* contents = browser_->GetSelectedTabContents(); - return (contents && contents->ShouldShowBookmarkBar()) ? YES : NO; + return (contents && + contents->ShouldShowBookmarkBar() && + ![previewableContentsController_ isShowingPreview]); } - (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression { diff --git a/chrome/browser/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar/location_bar_view_mac.h index 911fdc6..583925d 100644 --- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.h @@ -214,6 +214,9 @@ class LocationBarViewMac : public AutocompleteEditController, ToolbarModel* toolbar_model_; // Weak, owned by Browser. + // Whether or not to update the instant preview. + bool update_instant_; + // The transition type to use for the navigation. PageTransition::Type transition_; diff --git a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm index 15841d2..8a2bec5 100644 --- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm @@ -15,6 +15,7 @@ #include "chrome/browser/alternate_nav_url_fetcher.h" #import "chrome/browser/app_controller_mac.h" #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" +#import "chrome/browser/autocomplete/autocomplete_popup_model.h" #include "chrome/browser/browser_list.h" #import "chrome/browser/cocoa/content_setting_bubble_cocoa.h" #include "chrome/browser/cocoa/event_utils.h" @@ -37,6 +38,7 @@ #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/location_bar_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" @@ -82,6 +84,7 @@ LocationBarViewMac::LocationBarViewMac( profile_(profile), browser_(browser), toolbar_model_(toolbar_model), + update_instant_(true), transition_(PageTransition::TYPED), first_run_bubble_(this) { for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { @@ -125,8 +128,7 @@ std::wstring LocationBarViewMac::GetInputString() const { } void LocationBarViewMac::SetSuggestedText(const string16& text) { - // TODO: implement me. - NOTIMPLEMENTED(); + // TODO(rohitrao): implement me. http://crbug.com/56385 } WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { @@ -201,12 +203,35 @@ void LocationBarViewMac::Update(const TabContents* contents, } void LocationBarViewMac::OnAutocompleteWillClosePopup() { + if (!update_instant_) + return; + + InstantController* controller = browser_->instant(); + if (controller && !controller->commit_on_mouse_up()) + controller->DestroyPreviewContents(); } void LocationBarViewMac::OnAutocompleteLosingFocus(gfx::NativeView unused) { + InstantController* instant = browser_->instant(); + if (!instant) + return; + + if (!instant->is_active() || !instant->GetPreviewContents()) + return; + + // If |IsMouseDownFromActivate()| returns false, the RenderWidgetHostView did + // not receive a mouseDown event. Therefore, we should destroy the preview. + // Otherwise, the RWHV was clicked, so we commit the preview. + if (!instant->IsMouseDownFromActivate()) + instant->DestroyPreviewContents(); + else if (instant->IsShowingInstant()) + instant->SetCommitOnMouseUp(); + else + instant->CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); } void LocationBarViewMac::OnAutocompleteWillAccept() { + update_instant_ = false; } bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) { @@ -220,35 +245,39 @@ void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition, const GURL& alternate_nav_url) { - if (!url.is_valid()) - return; - - location_input_ = UTF8ToWide(url.spec()); - disposition_ = disposition; - transition_ = transition; - - if (!command_updater_) - return; - - if (!alternate_nav_url.is_valid()) { - command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); - return; + // WARNING: don't add an early return here. The calls after the if must + // happen. + if (url.is_valid()) { + location_input_ = UTF8ToWide(url.spec()); + disposition_ = disposition; + transition_ = transition; + + if (command_updater_) { + if (!alternate_nav_url.is_valid()) { + command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); + } else { + AlternateNavURLFetcher* fetcher = + new AlternateNavURLFetcher(alternate_nav_url); + // The AlternateNavURLFetcher will listen for the pending navigation + // notification that will be issued as a result of the "open URL." It + // will automatically install itself into that navigation controller. + command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); + if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) { + // I'm not sure this should be reachable, but I'm not also sure enough + // that it shouldn't to stick in a NOTREACHED(). In any case, this is + // harmless. + delete fetcher; + } else { + // The navigation controller will delete the fetcher. + } + } + } } - AlternateNavURLFetcher* fetcher = - new AlternateNavURLFetcher(alternate_nav_url); - // The AlternateNavURLFetcher will listen for the pending navigation - // notification that will be issued as a result of the "open URL." It - // will automatically install itself into that navigation controller. - command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); - if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) { - // I'm not sure this should be reachable, but I'm not also sure enough - // that it shouldn't to stick in a NOTREACHED(). In any case, this is - // harmless. - delete fetcher; - } else { - // The navigation controller will delete the fetcher. - } + if (browser_->instant()) + browser_->instant()->DestroyPreviewContents(); + + update_instant_ = true; } void LocationBarViewMac::OnChanged() { @@ -258,6 +287,21 @@ void LocationBarViewMac::OnChanged() { location_icon_decoration_->SetImage(image); ev_bubble_decoration_->SetImage(image); Layout(); + + InstantController* instant = browser_->instant(); + string16 suggested_text; + if (update_instant_ && instant && GetTabContents()) { + if (edit_view_->model()->user_input_in_progress() && + edit_view_->model()->popup_model()->IsOpen()) { + instant->Update(GetTabContents(), + edit_view_->model()->CurrentMatch(), + WideToUTF16(edit_view_->GetText()), + &suggested_text); + } else { + if (instant->is_active()) + instant->DestroyPreviewContents(); + } + } } void LocationBarViewMac::OnInputInProgress(bool in_progress) { diff --git a/chrome/browser/cocoa/previewable_contents_controller.mm b/chrome/browser/cocoa/previewable_contents_controller.mm index 99acd2c41..fc738c4 100644 --- a/chrome/browser/cocoa/previewable_contents_controller.mm +++ b/chrome/browser/cocoa/previewable_contents_controller.mm @@ -27,8 +27,12 @@ - (void)showPreview:(TabContents*)preview { DCHECK(preview); - previewContents_ = preview; + // Remove any old preview contents before showing the new one. + if (previewContents_) + [previewContents_->GetNativeView() removeFromSuperview]; + + previewContents_ = preview; NSView* previewView = previewContents_->GetNativeView(); [previewView setFrame:[[self view] bounds]]; diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 9085525..0fe9d26 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -80,6 +80,7 @@ TabContentsViewMac::~TabContentsViewMac() { void TabContentsViewMac::CreateView(const gfx::Size& initial_size) { TabContentsViewCocoa* view = [[TabContentsViewCocoa alloc] initWithTabContentsViewMac:this]; + [view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; cocoa_view_.reset(view); } |