Chromium Code Reviews| Index: ash/shelf/shelf_view.cc |
| diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc |
| index 41a6a5206217593370df8e867666ea992d0d567e..f57d53aef0c0dc3f545dd9ef7ded00f8463bbeae 100644 |
| --- a/ash/shelf/shelf_view.cc |
| +++ b/ash/shelf/shelf_view.cc |
| @@ -26,6 +26,7 @@ |
| #include "ash/shell_port.h" |
| #include "ash/strings/grit/ash_strings.h" |
| #include "ash/wm/root_window_finder.h" |
| +#include "ash/wm/wm_screen_util.h" |
| #include "ash/wm_window.h" |
| #include "base/auto_reset.h" |
| #include "base/memory/ptr_util.h" |
| @@ -1600,11 +1601,33 @@ void ShelfView::AfterItemSelected( |
| void ShelfView::ShowContextMenuForView(views::View* source, |
| const gfx::Point& point, |
| ui::MenuSourceType source_type) { |
| + WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); |
|
msw
2017/05/05 17:34:18
nit: add a comment to this block of code, like "Al
minch1
2017/05/08 17:21:02
Done.
|
| + gfx::Rect shelf_bounds = |
| + is_overflow_mode() |
| + ? (owner_overflow_bubble_->bubble_view()->GetBubbleBounds()) |
| + : (wm::GetDisplayBoundsInParent(shelf_window)); |
|
msw
2017/05/05 17:34:18
You'll probably need to refactor this as per https
|
| + |
| + gfx::Point point_aligned_shelf; |
|
msw
2017/05/05 17:34:18
nit: consider |menu_point| or |context_menu_point|
minch1
2017/05/08 17:21:02
Done.
|
| + switch (wm_shelf_->GetAlignment()) { |
| + case SHELF_ALIGNMENT_BOTTOM: |
| + case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| + point_aligned_shelf.SetPoint(point.x(), |
| + shelf_bounds.bottom() - kShelfSize); |
|
msw
2017/05/05 17:34:19
Why not just use shelf_bounds.y()?
minch1
2017/05/08 17:21:02
This is fine for overflow mode, if it is not. The
|
| + break; |
| + case SHELF_ALIGNMENT_LEFT: |
| + point_aligned_shelf.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); |
|
msw
2017/05/05 17:34:19
Ditto: why not just use shelf_bounds.right()?
|
| + break; |
| + case SHELF_ALIGNMENT_RIGHT: |
| + point_aligned_shelf.SetPoint(shelf_bounds.right() - kShelfSize, |
|
msw
2017/05/05 17:34:19
Ditto: why not just use shelf_bounds.x()?
|
| + point.y()); |
| + default: |
|
msw
2017/05/05 17:34:19
Remove the default case, so if anyone adds a new a
|
| + break; |
| + } |
| last_pressed_index_ = -1; |
| const ShelfItem* item = ShelfItemForView(source); |
| if (!item) { |
| - ShellPort::Get()->ShowContextMenu(point, source_type); |
| + ShellPort::Get()->ShowContextMenu(point_aligned_shelf, source_type); |
| return; |
| } |
| @@ -1614,8 +1637,8 @@ void ShelfView::ShowContextMenuForView(views::View* source, |
| return; |
| context_menu_id_ = item ? item->id : 0; |
| - ShowMenu(std::move(context_menu_model), source, point, true, source_type, |
| - nullptr); |
| + ShowMenu(std::move(context_menu_model), source, point_aligned_shelf, true, |
| + source_type, nullptr); |
| } |
| void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, |
| @@ -1644,6 +1667,7 @@ void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, |
| views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; |
| gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); |
| + ShelfAlignment shelf_alignment = wm_shelf_->GetAlignment(); |
| if (!context_menu) { |
| // Application lists use a bubble. |
| // It is possible to invoke the menu while it is sliding into view. To cover |
| @@ -1656,7 +1680,7 @@ void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, |
| anchor.Inset(source->border()->GetInsets()); |
| // Determine the menu alignment dependent on the shelf. |
| - switch (wm_shelf_->GetAlignment()) { |
| + switch (shelf_alignment) { |
| case SHELF_ALIGNMENT_BOTTOM: |
| case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| menu_alignment = views::MENU_ANCHOR_BUBBLE_ABOVE; |
| @@ -1670,6 +1694,13 @@ void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, |
| } |
| } |
| + // Distinguish the touch events that triggered on the bottom shelf or |
| + // left / right shelf. Since they should have different |MenuAnchorPosition|. |
| + if (source_type == ui::MENU_SOURCE_TOUCH && |
| + (shelf_alignment == SHELF_ALIGNMENT_LEFT || |
|
msw
2017/05/05 17:34:18
Use !WmShelf::IsHorizontalAlignment() instead, and
|
| + shelf_alignment == SHELF_ALIGNMENT_RIGHT)) { |
| + source_type = ui::MENU_SOURCE_TOUCH_SIDE_SHELF; |
| + } |
| // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. |
| launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, |
| menu_alignment, source_type); |
| @@ -1756,7 +1787,7 @@ bool ShelfView::CanPrepareForDrag(Pointer pointer, |
| return false; |
| } |
| - // Touch dragging only begins after a dealy from the press event. This |
| + // Touch dragging only begins after a delay from the press event. This |
| // prevents accidental dragging on swipe or scroll gestures. |
| if (pointer == TOUCH && |
| (base::TimeTicks::Now() - touch_press_time_) < |