diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 22:46:03 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 22:46:03 +0000 |
commit | 413df1b5ebacf0f3bc2ad03020e9f93b92717803 (patch) | |
tree | 92381b78a0b3a1682523b338428688bd4e23cd9e /chrome/browser/views | |
parent | 76665e75f3f10a3171efd3bebfbd9c59a7648a00 (diff) | |
download | chromium_src-413df1b5ebacf0f3bc2ad03020e9f93b92717803.zip chromium_src-413df1b5ebacf0f3bc2ad03020e9f93b92717803.tar.gz chromium_src-413df1b5ebacf0f3bc2ad03020e9f93b92717803.tar.bz2 |
Convert the AutocompletePopupPositioner into a BubblePositioner in preparation for using it to position both the Omnibox bubble and InfoBubbles. It now gets the bounds of the location stack, which can be turned into useful coordinates for both items.
This should not result in any visible change.
BUG=21028
TEST=none
Review URL: http://codereview.chromium.org/194110
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc | 25 | ||||
-rw-r--r-- | chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h | 7 | ||||
-rw-r--r-- | chrome/browser/views/bubble_border.cc | 24 | ||||
-rw-r--r-- | chrome/browser/views/bubble_border.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 8 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.h | 14 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 38 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.h | 8 |
8 files changed, 76 insertions, 54 deletions
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 2ca8f0d..7efee67 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -14,6 +14,7 @@ #include "base/compiler_specific.h" #include "chrome/browser/autocomplete/autocomplete_edit_view.h" #include "chrome/browser/autocomplete/autocomplete_popup_model.h" +#include "chrome/browser/bubble_positioner.h" #include "chrome/browser/views/bubble_border.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -582,7 +583,7 @@ AutocompletePopupContentsView::AutocompletePopupContentsView( AutocompleteEditView* edit_view, AutocompleteEditModel* edit_model, Profile* profile, - AutocompletePopupPositioner* popup_positioner) + const BubblePositioner* bubble_positioner) #if defined(OS_WIN) : popup_(new AutocompletePopupWin(this)), #else @@ -590,10 +591,14 @@ AutocompletePopupContentsView::AutocompletePopupContentsView( #endif model_(new AutocompletePopupModel(this, edit_model, profile)), edit_view_(edit_view), - popup_positioner_(popup_positioner), + bubble_positioner_(bubble_positioner), result_font_(font.DeriveFont(kEditFontAdjust)), ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { - set_border(new BubbleBorder); + // The following little dance is required because set_border() requires a + // pointer to a non-const object. + BubbleBorder* bubble_border = new BubbleBorder; + bubble_border_ = bubble_border; + set_border(bubble_border); } gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { @@ -650,12 +655,10 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() { } // Calculate desired bounds. - gfx::Rect new_target_bounds = popup_positioner_->GetPopupBounds(); - new_target_bounds.set_height(total_child_height); - gfx::Insets insets; - border()->GetInsets(&insets); - new_target_bounds.Inset(-insets.left(), -insets.top(), -insets.right(), - -insets.bottom()); + gfx::Rect location_stack_bounds = + bubble_positioner_->GetLocationStackBounds(); + gfx::Rect new_target_bounds(bubble_border_->GetBounds(location_stack_bounds, + gfx::Size(location_stack_bounds.width(), total_child_height))); // If we're animating and our target height changes, reset the animation. // NOTE: If we just reset blindly on _every_ update, then when the user types @@ -870,7 +873,7 @@ AutocompletePopupView* AutocompletePopupView::CreatePopupView( AutocompleteEditView* edit_view, AutocompleteEditModel* edit_model, Profile* profile, - AutocompletePopupPositioner* popup_positioner) { + const BubblePositioner* bubble_positioner) { return new AutocompletePopupContentsView(font, edit_view, edit_model, - profile, popup_positioner); + profile, bubble_positioner); } diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h index b8baf1b..d5f710e 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h @@ -55,7 +55,7 @@ class AutocompletePopupContentsView : public views::View, AutocompleteEditView* edit_view, AutocompleteEditModel* edit_model, Profile* profile, - AutocompletePopupPositioner* popup_positioner); + const BubblePositioner* bubble_positioner); virtual ~AutocompletePopupContentsView() {} // Returns the bounds the popup should be shown at. This is the display bounds @@ -117,7 +117,10 @@ class AutocompletePopupContentsView : public views::View, AutocompleteEditView* edit_view_; // An object that tells the popup how to position itself. - AutocompletePopupPositioner* popup_positioner_; + const BubblePositioner* bubble_positioner_; + + // Our border, which can compute our desired bounds. + const BubbleBorder* bubble_border_; // The font that we should use for result rows. This is based on the font used // by the edit that created us. diff --git a/chrome/browser/views/bubble_border.cc b/chrome/browser/views/bubble_border.cc index eaf27c1..8bf0170 100644 --- a/chrome/browser/views/bubble_border.cc +++ b/chrome/browser/views/bubble_border.cc @@ -21,10 +21,27 @@ SkBitmap* BubbleBorder::bottom_right_ = NULL; SkBitmap* BubbleBorder::bottom_ = NULL; SkBitmap* BubbleBorder::bottom_left_ = NULL; +gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& position_relative_to, + const gfx::Size& contents_size) const { + // The spacing (in pixels) between |position_relative_to| and the bubble + // content. + const int kBubbleSpacing = 2; + + // Desired size is size of contents enlarged by the size of the border images. + gfx::Size border_size(contents_size); + gfx::Insets insets; + GetInsets(&insets); + border_size.Enlarge(insets.left() + insets.right(), + insets.top() + insets.bottom()); + + int x = position_relative_to.x() + (position_relative_to.width() / 2) - + (contents_size.width() / 2) - insets.left(); + int y = position_relative_to.bottom() - (top_->height() - kBubbleSpacing); + + return gfx::Rect(x, y, border_size.width(), border_size.height()); +} + void BubbleBorder::GetInsets(gfx::Insets* insets) const { - // The left, right and bottom edge image sizes define our insets. The corner - // images don't determine this because they can extend inside the border (onto - // the contained contents). insets->Set(top_->height(), left_->width(), bottom_->height(), right_->width()); } @@ -109,6 +126,7 @@ void BubbleBorder::Paint(const views::View& view, gfx::Canvas* canvas) const { // Bottom edge canvas->TileImageInt(*bottom_, bl_width, bottom, width - bl_width - br_width, b_height); + // Bottom left corner canvas->DrawBitmapInt(*bottom_left_, 0, bl_y); diff --git a/chrome/browser/views/bubble_border.h b/chrome/browser/views/bubble_border.h index 2febe83..7b0ee47 100644 --- a/chrome/browser/views/bubble_border.h +++ b/chrome/browser/views/bubble_border.h @@ -27,6 +27,12 @@ class BubbleBorder : public views::Border { return 4; } + // Gives the desired bounds (in screen coordinates) given the rect to position + // relative to and the size of the contained contents. The contents are + // centered underneath the supplied rect. + gfx::Rect GetBounds(const gfx::Rect& position_relative_to, + const gfx::Size& contents_size) const; + // Overridden from views::Border: virtual void GetInsets(gfx::Insets* insets) const; diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index b607c06..267423b 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -86,7 +86,7 @@ LocationBarView::LocationBarView(Profile* profile, ToolbarModel* model, Delegate* delegate, bool popup_window_mode, - AutocompletePopupPositioner* popup_positioner) + const BubblePositioner* bubble_positioner) : profile_(profile), command_updater_(command_updater), model_(model), @@ -99,7 +99,7 @@ LocationBarView::LocationBarView(Profile* profile, security_image_view_(profile, model), popup_window_mode_(popup_window_mode), first_run_bubble_(this), - popup_positioner_(popup_positioner) { + bubble_positioner_(bubble_positioner) { DCHECK(profile_); SetID(VIEW_ID_LOCATION_BAR); SetFocusable(true); @@ -138,12 +138,12 @@ void LocationBarView::Init() { widget->GetNativeView(), profile_, command_updater_, popup_window_mode_, - popup_positioner_)); + bubble_positioner_)); #else location_entry_.reset(new AutocompleteEditViewGtk(this, model_, profile_, command_updater_, popup_window_mode_, - popup_positioner_)); + bubble_positioner_)); location_entry_->Init(); // Make all the children of the widget visible. NOTE: this won't display // anything, it just toggles the visible flag. diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index a9e0a54..b72eca5 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -27,7 +27,7 @@ #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" #endif -class AutocompletePopupPositioner; +class BubblePositioner; class CommandUpdater; class GURL; class PageAction; @@ -73,7 +73,7 @@ class LocationBarView : public LocationBar, ToolbarModel* model, Delegate* delegate, bool popup_window_mode, - AutocompletePopupPositioner* popup_positioner); + const BubblePositioner* bubble_positioner); virtual ~LocationBarView(); void Init(); @@ -339,9 +339,9 @@ class LocationBarView : public LocationBar, class PageActionImageView : public LocationBarImageView, public ImageLoadingTracker::Observer { public: - PageActionImageView( - LocationBarView* owner, Profile* profile, - const PageAction* page_action); + PageActionImageView(LocationBarView* owner, + Profile* profile, + const PageAction* page_action); virtual ~PageActionImageView(); // Overridden from view for the mouse hovering. @@ -518,8 +518,8 @@ class LocationBarView : public LocationBar, // Used schedule a task for the first run info bubble. ScopedRunnableMethodFactory<LocationBarView> first_run_bubble_; - // The positioner that places the autocomplete popup. - AutocompletePopupPositioner* popup_positioner_; + // The positioner that places the omnibox and info bubbles. + const BubblePositioner* bubble_positioner_; // Storage of string needed for accessibility. std::wstring accessible_name_; diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 9ce0ef5..b32a608 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -67,14 +67,6 @@ static const int kPopupTopSpacingNonGlass = 3; static const int kPopupBottomSpacingNonGlass = 2; static const int kPopupBottomSpacingGlass = 1; -// The vertical distance between the bottom of the omnibox and the top of the -// popup. -static const int kOmniboxPopupVerticalSpacing = 2; -// The number of pixels of margin on the buttons on either side of the omnibox. -// We use this value to inset the bounds returned for the omnibox popup, since -// we want the popup to be only as wide as the visible frame of the omnibox. -static const int kOmniboxButtonsHorizontalMargin = 2; - static SkBitmap* kPopupBackgroundEdge = NULL; //////////////////////////////////////////////////////////////////////////////// @@ -364,27 +356,27 @@ void ToolbarView::ButtonPressed( } //////////////////////////////////////////////////////////////////////////////// -// ToolbarView, AutocompletePopupPositioner implementation: +// ToolbarView, BubblePositioner implementation: + +gfx::Rect ToolbarView::GetLocationStackBounds() const { + // The number of pixels from the left or right edges of the location stack to + // "just inside the visible borders". When the omnibox bubble contents are + // aligned with this, the visible borders tacked on to the outsides will line + // up with the visible borders on the location stack. + const int kLocationStackEdgeWidth = 2; -gfx::Rect ToolbarView::GetPopupBounds() const { gfx::Point origin; views::View::ConvertPointToScreen(star_, &origin); - origin.set_y(origin.y() + star_->height() + kOmniboxPopupVerticalSpacing); - gfx::Rect popup_bounds(origin.x(), origin.y(), + gfx::Rect stack_bounds(origin.x(), origin.y(), star_->width() + location_bar_->width() + go_->width(), - 0); + location_bar_->height()); if (UILayoutIsRightToLeft()) { - popup_bounds.set_x( - popup_bounds.x() - location_bar_->width() - go_->width()); - } else { - popup_bounds.set_x(popup_bounds.x()); + stack_bounds.set_x( + stack_bounds.x() - location_bar_->width() - go_->width()); } - popup_bounds.set_y(popup_bounds.y()); - popup_bounds.set_width(popup_bounds.width()); - // Inset the bounds a little, since the buttons on either edge of the omnibox - // have invisible padding that makes the popup appear too wide. - popup_bounds.Inset(kOmniboxButtonsHorizontalMargin, 0); - return popup_bounds; + // Inset the bounds to just inside the visible edges (see comment above). + stack_bounds.Inset(kLocationStackEdgeWidth, 0); + return stack_bounds; } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index 051b22d..ed42a11 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -9,9 +9,9 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "chrome/browser/bubble_positioner.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/user_data_manager.h" -#include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" #include "chrome/browser/views/go_button.h" #include "chrome/browser/views/location_bar_view.h" #include "chrome/common/pref_member.h" @@ -72,7 +72,7 @@ class ToolbarView : public views::View, public GetProfilesHelper::Delegate, public CommandUpdater::CommandObserver, public views::ButtonListener, - public AutocompletePopupPositioner { + public BubblePositioner { public: explicit ToolbarView(Browser* browser); virtual ~ToolbarView(); @@ -128,8 +128,8 @@ class ToolbarView : public views::View, // Overridden from views::BaseButton::ButtonListener: virtual void ButtonPressed(views::Button* sender, const views::Event& event); - // Overridden from AutocompletePopupPositioner: - virtual gfx::Rect GetPopupBounds() const; + // BubblePositioner: + virtual gfx::Rect GetLocationStackBounds() const; // Overridden from NotificationObserver: virtual void Observe(NotificationType type, |