diff options
author | asanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 15:02:50 +0000 |
---|---|---|
committer | asanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 15:02:50 +0000 |
commit | 2dc149b799c69a6594d426385852503a679e4c4d (patch) | |
tree | e53bd6c86e33571f09235074c022ad7f9e349b84 | |
parent | 4011106e247759fffcae703dacfca48f519413b9 (diff) | |
download | chromium_src-2dc149b799c69a6594d426385852503a679e4c4d.zip chromium_src-2dc149b799c69a6594d426385852503a679e4c4d.tar.gz chromium_src-2dc149b799c69a6594d426385852503a679e4c4d.tar.bz2 |
Merge 107396 - Set bounds of download shelf drop down menu so that it doesn't overlap the button.
BUG=101080
TEST=Download shelf drop down menu is positioned above or below the item view area, but not over it.
Review URL: http://codereview.chromium.org/8392029
TBR=asanka@chromium.org
Review URL: http://codereview.chromium.org/8437054
git-svn-id: svn://svn.chromium.org/chrome/branches/912/src@108292 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 21 insertions, 23 deletions
diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc index 88670ea..680717b 100644 --- a/chrome/browser/ui/views/download/download_item_view.cc +++ b/chrome/browser/ui/views/download/download_item_view.cc @@ -466,21 +466,19 @@ bool DownloadItemView::OnMousePressed(const views::MouseEvent& event) { if (complete_animation_.get() && complete_animation_->is_animating()) complete_animation_->End(); - gfx::Point menu_location(event.location()); if (event.IsOnlyLeftMouseButton()) { - if (!InDropDownButtonXCoordinateRange(event.x())) { + if (InDropDownButtonXCoordinateRange(event.x())) { + drop_down_pressed_ = true; + SetState(NORMAL, PUSHED); + // We are setting is_mouse_gesture to false when calling ShowContextMenu + // so that the positioning of the context menu will be similar to a + // keyboard invocation. I.e. we want the menu to always be positioned + // next to the drop down button instead of the next to the pointer. + ShowContextMenu(event.location(), false); + } else { SetState(PUSHED, NORMAL); - return true; } - - // Anchor the menu below the dropmarker. - menu_location.SetPoint(base::i18n::IsRTL() ? - drop_down_x_right_ : drop_down_x_left_, - height()); - drop_down_pressed_ = true; - SetState(NORMAL, PUSHED); } - ShowContextMenu(menu_location, true); return true; } @@ -591,6 +589,7 @@ bool DownloadItemView::GetTooltipText(const gfx::Point& p, void DownloadItemView::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { gfx::Point point = p; + gfx::Size size; // Similar hack as in MenuButton. // We're about to show the menu from a mouse press. By showing from the @@ -608,12 +607,8 @@ void DownloadItemView::ShowContextMenu(const gfx::Point& p, if (!is_mouse_gesture) { drop_down_pressed_ = true; SetState(NORMAL, PUSHED); - - point.set_y(height()); - if (base::i18n::IsRTL()) - point.set_x(drop_down_x_right_); - else - point.set_x(drop_down_x_left_); + point.SetPoint(drop_down_x_left_, box_y_); + size.SetSize(drop_down_x_right_ - drop_down_x_left_, box_height_); } views::View::ConvertPointToScreen(this, &point); @@ -622,7 +617,8 @@ void DownloadItemView::ShowContextMenu(const gfx::Point& p, context_menu_.reset(new DownloadShelfContextMenuView(model_.get())); // When we call the Run method on the menu, it runs an inner message loop // that might causes us to be deleted. - if (context_menu_->Run(GetWidget()->GetTopLevelWidget(), point)) + if (context_menu_->Run(GetWidget()->GetTopLevelWidget(), + gfx::Rect(point, size))) return; // We have been deleted! Don't access 'this'. // If the menu action was to remove the download, this view will also be diff --git a/chrome/browser/ui/views/download/download_shelf_context_menu_view.cc b/chrome/browser/ui/views/download/download_shelf_context_menu_view.cc index dd6683b..849d1db 100644 --- a/chrome/browser/ui/views/download/download_shelf_context_menu_view.cc +++ b/chrome/browser/ui/views/download/download_shelf_context_menu_view.cc @@ -22,7 +22,7 @@ DownloadShelfContextMenuView::DownloadShelfContextMenuView( DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {} bool DownloadShelfContextMenuView::Run(views::Widget* parent_widget, - const gfx::Point& point) { + const gfx::Rect& rect) { views::MenuModelAdapter menu_model_adapter(GetMenuModel()); menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); @@ -35,7 +35,7 @@ bool DownloadShelfContextMenuView::Run(views::Widget* parent_widget, return menu_runner_->RunMenuAt( parent_widget, NULL, - gfx::Rect(point, gfx::Size()), + rect, position, views::MenuRunner::HAS_MNEMONICS) == views::MenuRunner::MENU_DELETED; } diff --git a/chrome/browser/ui/views/download/download_shelf_context_menu_view.h b/chrome/browser/ui/views/download/download_shelf_context_menu_view.h index 0ec57b9..8f59f42 100644 --- a/chrome/browser/ui/views/download/download_shelf_context_menu_view.h +++ b/chrome/browser/ui/views/download/download_shelf_context_menu_view.h @@ -14,7 +14,7 @@ class BaseDownloadItemModel; namespace gfx { -class Point; +class Rect; } namespace views { @@ -27,9 +27,11 @@ class DownloadShelfContextMenuView : public DownloadShelfContextMenu { explicit DownloadShelfContextMenuView(BaseDownloadItemModel* model); virtual ~DownloadShelfContextMenuView(); - // Returns true if menu has been deleted. + // Returns true if menu has been deleted. |rect| is the bounding area for + // positioning the menu in screen coordinates. The menu will be positioned + // above or below but not overlapping |rect|. bool Run(views::Widget* parent_widget, - const gfx::Point& point) WARN_UNUSED_RESULT; + const gfx::Rect& rect) WARN_UNUSED_RESULT; // This method runs when the caller has been deleted and we should not attempt // to access download_item(). |