Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: ash/shelf/shelf_view.cc

Issue 2861873002: Align the base of the shelf's context menu to the top edge of the shelf. (Closed)
Patch Set: Rebased and adressed comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/shelf/shelf_view.cc
diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc
index d2de17bb6a394191b941af37f8896dd32f8b07f3..0d052d712d0cb69dbf76a6e415bf5d1dd10ab2fc 100644
--- a/ash/shelf/shelf_view.cc
+++ b/ash/shelf/shelf_view.cc
@@ -11,6 +11,7 @@
#include "ash/drag_drop/drag_image_view.h"
#include "ash/public/cpp/shelf_item_delegate.h"
#include "ash/scoped_root_window_for_new_windows.h"
+#include "ash/screen_util.h"
#include "ash/shelf/app_list_button.h"
#include "ash/shelf/overflow_bubble.h"
#include "ash/shelf/overflow_bubble_view.h"
@@ -1639,11 +1640,32 @@ void ShelfView::AfterItemSelected(
void ShelfView::ShowContextMenuForView(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
+ // Align the context menu to the edge of the shelf.
+ aura::Window* shelf_window = shelf_widget_->GetNativeWindow();
+ gfx::Rect shelf_bounds =
+ is_overflow_mode()
+ ? (owner_overflow_bubble_->bubble_view()->GetBubbleBounds())
+ : (ScreenUtil::GetDisplayBoundsWithShelf(shelf_window));
+
+ gfx::Point context_menu_point;
+ switch (wm_shelf_->GetAlignment()) {
+ case SHELF_ALIGNMENT_BOTTOM:
+ case SHELF_ALIGNMENT_BOTTOM_LOCKED:
+ context_menu_point.SetPoint(point.x(),
+ shelf_bounds.bottom() - kShelfSize);
+ break;
+ case SHELF_ALIGNMENT_LEFT:
+ context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y());
+ break;
+ case SHELF_ALIGNMENT_RIGHT:
+ context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, point.y());
+ break;
+ }
last_pressed_index_ = -1;
const ShelfItem* item = ShelfItemForView(source);
if (!item) {
- ShellPort::Get()->ShowContextMenu(point, source_type);
+ ShellPort::Get()->ShowContextMenu(context_menu_point, source_type);
return;
}
@@ -1653,8 +1675,8 @@ void ShelfView::ShowContextMenuForView(views::View* source,
return;
context_menu_id_ = item ? item->id : ShelfID();
- ShowMenu(std::move(context_menu_model), source, point, true, source_type,
- nullptr);
+ ShowMenu(std::move(context_menu_model), source, context_menu_point, true,
+ source_type, nullptr);
}
void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model,
@@ -1709,6 +1731,14 @@ 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) {
+ if (wm_shelf_->IsHorizontalAlignment())
+ source_type = ui::MENU_SOURCE_TOUCH_BOTTOM_ANCHOR;
+ else
+ source_type = ui::MENU_SOURCE_TOUCH_SIDE_ANCHOR;
+ }
// 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);
@@ -1795,7 +1825,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_) <

Powered by Google App Engine
This is Rietveld 408576698