diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-14 15:09:51 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-14 15:09:51 +0000 |
commit | 6af4014c7c0af5efc058aa9789c9d302c2f7873a (patch) | |
tree | d71c355805e37fd01a6fdd75b5aff7c2954fa781 | |
parent | 11540af83d79c15475afadf8fc98822e3c3ca2c8 (diff) | |
download | chromium_src-6af4014c7c0af5efc058aa9789c9d302c2f7873a.zip chromium_src-6af4014c7c0af5efc058aa9789c9d302c2f7873a.tar.gz chromium_src-6af4014c7c0af5efc058aa9789c9d302c2f7873a.tar.bz2 |
[Mac] Plumb through the Instant and omnibox popup bounds. This will allow instant results to properly move out of the way of the omnibox.
BUG=56385
TEST=Do a Google search with Instant turned on. The omnibox should not overlap with the results.
Review URL: http://codereview.chromium.org/3735005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62550 0039d316-1c4b-4281-b951-d872f2087c98
11 files changed, 55 insertions, 11 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index 46bab39..e313040 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -858,6 +858,7 @@ void AutocompleteEditViewMac::OnFrameChanged() { // things even cheaper by refactoring between the popup-placement // code and the matrix-population code. popup_view_->UpdatePopupAppearance(); + model_->PopupBoundsChangedTo(popup_view_->GetTargetBounds()); // Give controller a chance to rearrange decorations. controller_->OnChanged(); diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index 7456ccd..a92d0d8 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -292,12 +292,7 @@ void AutocompletePopupModel::Observe(NotificationType type, SetHoveredLine(kNoMatch); view_->UpdatePopupAppearance(); - -#if defined(TOOLKIT_VIEWS) edit_model_->PopupBoundsChangedTo(view_->GetTargetBounds()); -#else - // TODO: port -#endif } const SkBitmap* AutocompletePopupModel::GetSpecialIconForMatch( diff --git a/chrome/browser/autocomplete/autocomplete_popup_view.h b/chrome/browser/autocomplete/autocomplete_popup_view.h index 279d63d..71f6c8d 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view.h +++ b/chrome/browser/autocomplete/autocomplete_popup_view.h @@ -14,6 +14,10 @@ #include "build/build_config.h" +namespace gfx { +class Rect; +} + class AutocompletePopupModel; class AutocompletePopupView { @@ -30,12 +34,10 @@ class AutocompletePopupView { // mean opening or closing the window. virtual void UpdatePopupAppearance() = 0; -#if defined(TOOLKIT_VIEWS) // Returns the target bounds for the popup. This returns the popup's current // bounds when not animating, or the desired target bounds when animating. // The return value is in screen coordinates. virtual gfx::Rect GetTargetBounds() = 0; -#endif // Paint any pending updates. virtual void PaintUpdatesNow() = 0; diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc index 5bb4f90..056b847 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc @@ -355,6 +355,12 @@ void AutocompletePopupViewGtk::UpdatePopupAppearance() { gtk_widget_queue_draw(window_); } +gfx::Rect AutocompletePopupViewGtk::GetTargetBounds() { + NOTIMPLEMENTED(); + return gfx::Rect(); +} + + void AutocompletePopupViewGtk::PaintUpdatesNow() { // Paint our queued invalidations now, synchronously. gdk_window_process_updates(window_->window, FALSE); diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h index 53adbc2..7684c37 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h @@ -37,6 +37,7 @@ class AutocompletePopupViewGtk : public AutocompletePopupView, virtual bool IsOpen() const { return opened_; } virtual void InvalidateLine(size_t line); virtual void UpdatePopupAppearance(); + virtual gfx::Rect GetTargetBounds(); virtual void PaintUpdatesNow(); virtual void OnDragCanceled(); virtual AutocompletePopupModel* GetModel(); diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h index e0a27d5..8e2de8c 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h +++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h @@ -62,6 +62,8 @@ class AutocompletePopupViewMac : public AutocompletePopupView { } virtual void UpdatePopupAppearance(); + virtual gfx::Rect GetTargetBounds(); + // Set |line| to be selected. void SetSelectedLine(size_t line); diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm index c1efe82..a6c7bb7 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm @@ -260,7 +260,8 @@ AutocompletePopupViewMac::AutocompletePopupViewMac( : model_(new AutocompletePopupModel(this, edit_model, profile)), edit_view_(edit_view), field_(field), - popup_(nil) { + popup_(nil), + targetPopupFrame_(NSZeroRect) { DCHECK(edit_view); DCHECK(edit_model); DCHECK(profile); @@ -448,6 +449,15 @@ void AutocompletePopupViewMac::UpdatePopupAppearance() { PositionPopup(rows * cellHeight); } +gfx::Rect AutocompletePopupViewMac::GetTargetBounds() { + // Flip the coordinate system before returning. + NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; + NSRect monitorFrame = [screen frame]; + gfx::Rect bounds(NSRectToCGRect(targetPopupFrame_)); + bounds.set_y(monitorFrame.size.height - bounds.y() - bounds.height()); + return bounds; +} + void AutocompletePopupViewMac::SetSelectedLine(size_t line) { model_->SetSelectedLine(line, false); } diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 108a9269..d339e9d 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -573,9 +573,13 @@ void BrowserWindowCocoa::HideInstant() { } gfx::Rect BrowserWindowCocoa::GetInstantBounds() { - // TODO: implement me - NOTIMPLEMENTED(); - return gfx::Rect(); + // Flip coordinates based on the primary screen. + NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; + NSRect monitorFrame = [screen frame]; + NSRect frame = [controller_ instantFrame]; + gfx::Rect bounds(NSRectToCGRect(frame)); + bounds.set_y(NSHeight(monitorFrame) - bounds.y() - bounds.height()); + return bounds; } void BrowserWindowCocoa::Observe(NotificationType type, diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 27264d7..4825bbf 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -265,6 +265,11 @@ class TabContents; - (void)showInstant:(TabContents*)previewContents; - (void)hideInstant; +// Returns the frame, in Cocoa (unflipped) screen coordinates, of the area where +// Instant results are. If Instant is not showing, returns the frame of where +// it would be. +- (NSRect)instantFrame; + // 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 86f3b5e..f0e2e9f 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -1738,6 +1738,21 @@ willAnimateFromState:(bookmarks::VisualState)oldState [self updateBookmarkBarVisibilityWithAnimation:NO]; } +- (NSRect)instantFrame { + // The view's bounds are in its own coordinate system. Convert that to the + // window base coordinate system, then translate it into the screen's + // coordinate system. + NSView* view = [previewableContentsController_ view]; + if (!view) + return NSZeroRect; + + NSRect frame = [view convertRect:[view bounds] toView:nil]; + NSPoint originInScreenCoords = + [[view window] convertBaseToScreen:frame.origin]; + frame.origin = originInScreenCoords; + return frame; +} + - (void)sheetDidEnd:(NSWindow*)sheet returnCode:(NSInteger)code context:(void*)context { 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 8a2bec5..e20a50f 100644 --- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm @@ -239,6 +239,9 @@ bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) { } void LocationBarViewMac::OnPopupBoundsChanged(const gfx::Rect& bounds) { + InstantController* instant = browser_->instant(); + if (instant) + instant->SetOmniboxBounds(bounds); } void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, |