Commit e7dcdc6d authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

Convert enum to enum class for MenuPart::Type

Use enum class instead of enum for MenuPart::Type.
enum class is more type safety.

Bug: 940736
Change-Id: I7b412d7b61584b80a9f9b20c22ecf69533288203
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543535
Commit-Queue: Hwanseung Lee <hs1217.lee@samsung.com>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828583}
parent 3231d73b
...@@ -386,7 +386,7 @@ class MenuController::MenuScrollTask { ...@@ -386,7 +386,7 @@ class MenuController::MenuScrollTask {
} }
DCHECK(part.submenu); DCHECK(part.submenu);
SubmenuView* new_menu = part.submenu; SubmenuView* new_menu = part.submenu;
bool new_is_up = (part.type == MenuController::MenuPart::SCROLL_UP); bool new_is_up = (part.type == MenuController::MenuPart::Type::kScrollUp);
if (new_menu == submenu_ && is_scrolling_up_ == new_is_up) if (new_menu == submenu_ && is_scrolling_up_ == new_is_up)
return; return;
...@@ -734,7 +734,7 @@ bool MenuController::OnMouseDragged(SubmenuView* source, ...@@ -734,7 +734,7 @@ bool MenuController::OnMouseDragged(SubmenuView* source,
return true; return true;
} }
MenuItemView* mouse_menu = nullptr; MenuItemView* mouse_menu = nullptr;
if (part.type == MenuPart::MENU_ITEM) { if (part.type == MenuPart::Type::kMenuItem) {
// If there is no menu target, but a submenu target, then we are interacting // If there is no menu target, but a submenu target, then we are interacting
// with an empty menu item within a submenu. These cannot become selection // with an empty menu item within a submenu. These cannot become selection
// targets for mouse interaction, so do not attempt to update selection. // targets for mouse interaction, so do not attempt to update selection.
...@@ -745,7 +745,7 @@ bool MenuController::OnMouseDragged(SubmenuView* source, ...@@ -745,7 +745,7 @@ bool MenuController::OnMouseDragged(SubmenuView* source,
mouse_menu = part.menu; mouse_menu = part.menu;
SetSelection(part.menu ? part.menu : state_.item, SELECTION_OPEN_SUBMENU); SetSelection(part.menu ? part.menu : state_.item, SELECTION_OPEN_SUBMENU);
} }
} else if (part.type == MenuPart::NONE) { } else if (part.type == MenuPart::Type::kNone) {
// If there is a sibling menu, show it. Otherwise, if the user has selected // If there is a sibling menu, show it. Otherwise, if the user has selected
// a menu item with no accompanying sibling menu or submenu, move selection // a menu item with no accompanying sibling menu or submenu, move selection
// back to the parent menu item. // back to the parent menu item.
...@@ -788,7 +788,7 @@ void MenuController::OnMouseReleased(SubmenuView* source, ...@@ -788,7 +788,7 @@ void MenuController::OnMouseReleased(SubmenuView* source,
DCHECK(state_.item); DCHECK(state_.item);
possible_drag_ = false; possible_drag_ = false;
MenuPart part = GetMenuPart(source, event.location()); MenuPart part = GetMenuPart(source, event.location());
if (event.IsRightMouseButton() && part.type == MenuPart::MENU_ITEM) { if (event.IsRightMouseButton() && part.type == MenuPart::Type::kMenuItem) {
MenuItemView* menu = part.menu; MenuItemView* menu = part.menu;
// |menu| is null means this event is from an empty menu or a separator. // |menu| is null means this event is from an empty menu or a separator.
// If it is from an empty menu, use parent context menu instead of that. // If it is from an empty menu, use parent context menu instead of that.
...@@ -844,7 +844,7 @@ void MenuController::OnMouseReleased(SubmenuView* source, ...@@ -844,7 +844,7 @@ void MenuController::OnMouseReleased(SubmenuView* source,
Accept(part.menu, event.flags()); Accept(part.menu, event.flags());
return; return;
} }
} else if (part.type == MenuPart::MENU_ITEM) { } else if (part.type == MenuPart::Type::kMenuItem) {
// User either clicked on empty space, or a menu that has children. // User either clicked on empty space, or a menu that has children.
SetSelection(part.menu ? part.menu : state_.item, SetSelection(part.menu ? part.menu : state_.item,
SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY);
...@@ -940,7 +940,7 @@ void MenuController::OnGestureEvent(SubmenuView* source, ...@@ -940,7 +940,7 @@ void MenuController::OnGestureEvent(SubmenuView* source,
SetSelectionOnPointerDown(source, event); SetSelectionOnPointerDown(source, event);
event->StopPropagation(); event->StopPropagation();
} else if (event->type() == ui::ET_GESTURE_LONG_PRESS) { } else if (event->type() == ui::ET_GESTURE_LONG_PRESS) {
if (part.type == MenuPart::MENU_ITEM && part.menu) { if (part.type == MenuPart::Type::kMenuItem && part.menu) {
gfx::Point screen_location(event->location()); gfx::Point screen_location(event->location());
View::ConvertPointToScreen(source->GetScrollViewContainer(), View::ConvertPointToScreen(source->GetScrollViewContainer(),
&screen_location); &screen_location);
...@@ -955,14 +955,14 @@ void MenuController::OnGestureEvent(SubmenuView* source, ...@@ -955,14 +955,14 @@ void MenuController::OnGestureEvent(SubmenuView* source,
Accept(part.menu, event->flags()); Accept(part.menu, event->flags());
} }
event->StopPropagation(); event->StopPropagation();
} else if (part.type == MenuPart::MENU_ITEM) { } else if (part.type == MenuPart::Type::kMenuItem) {
// User either tapped on empty space, or a menu that has children. // User either tapped on empty space, or a menu that has children.
SetSelection(part.menu ? part.menu : state_.item, SetSelection(part.menu ? part.menu : state_.item,
SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY);
event->StopPropagation(); event->StopPropagation();
} }
} else if (event->type() == ui::ET_GESTURE_TAP_CANCEL && part.menu && } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL && part.menu &&
part.type == MenuPart::MENU_ITEM) { part.type == MenuPart::Type::kMenuItem) {
// Move the selection to the parent menu so that the selection in the // Move the selection to the parent menu so that the selection in the
// current menu is unset. Make sure the submenu remains open by sending the // current menu is unset. Make sure the submenu remains open by sending the
// appropriate SetSelectionTypes flags. // appropriate SetSelectionTypes flags.
...@@ -986,7 +986,7 @@ void MenuController::OnTouchEvent(SubmenuView* source, ui::TouchEvent* event) { ...@@ -986,7 +986,7 @@ void MenuController::OnTouchEvent(SubmenuView* source, ui::TouchEvent* event) {
if (event->type() == ui::ET_TOUCH_PRESSED) { if (event->type() == ui::ET_TOUCH_PRESSED) {
MenuPart part = GetMenuPart(source, event->location()); MenuPart part = GetMenuPart(source, event->location());
if (part.type == MenuPart::NONE) { if (part.type == MenuPart::Type::kNone) {
RepostEventAndCancel(source, event); RepostEventAndCancel(source, event);
event->SetHandled(); event->SetHandled();
} }
...@@ -1152,7 +1152,7 @@ int MenuController::OnPerformDrop(SubmenuView* source, ...@@ -1152,7 +1152,7 @@ int MenuController::OnPerformDrop(SubmenuView* source,
void MenuController::OnDragEnteredScrollButton(SubmenuView* source, void MenuController::OnDragEnteredScrollButton(SubmenuView* source,
bool is_up) { bool is_up) {
MenuPart part; MenuPart part;
part.type = is_up ? MenuPart::SCROLL_UP : MenuPart::SCROLL_DOWN; part.type = is_up ? MenuPart::Type::kScrollUp : MenuPart::Type::kScrollDown;
part.submenu = source; part.submenu = source;
UpdateScrolling(part); UpdateScrolling(part);
...@@ -1458,8 +1458,8 @@ void MenuController::SetSelectionOnPointerDown(SubmenuView* source, ...@@ -1458,8 +1458,8 @@ void MenuController::SetSelectionOnPointerDown(SubmenuView* source,
(event->flags() & ui::EF_FROM_TOUCH)) (event->flags() & ui::EF_FROM_TOUCH))
return; return;
if (part.type == MenuPart::NONE || if (part.type == MenuPart::Type::kNone ||
(part.type == MenuPart::MENU_ITEM && part.menu && (part.type == MenuPart::Type::kMenuItem && part.menu &&
part.menu->GetRootMenuItem() != state_.item->GetRootMenuItem())) { part.menu->GetRootMenuItem() != state_.item->GetRootMenuItem())) {
// Remember the time stamp of the current (press down) event. The owner can // Remember the time stamp of the current (press down) event. The owner can
// then use this to figure out if this menu was finished with the same click // then use this to figure out if this menu was finished with the same click
...@@ -1896,11 +1896,11 @@ bool MenuController::IsScrollButtonAt(SubmenuView* source, ...@@ -1896,11 +1896,11 @@ bool MenuController::IsScrollButtonAt(SubmenuView* source,
scroll_view->GetEventHandlerForPoint(gfx::Point(x, y)); scroll_view->GetEventHandlerForPoint(gfx::Point(x, y));
if (child_under_mouse && child_under_mouse->GetEnabled()) { if (child_under_mouse && child_under_mouse->GetEnabled()) {
if (child_under_mouse == scroll_view->scroll_up_button()) { if (child_under_mouse == scroll_view->scroll_up_button()) {
*part = MenuPart::SCROLL_UP; *part = MenuPart::Type::kScrollUp;
return true; return true;
} }
if (child_under_mouse == scroll_view->scroll_down_button()) { if (child_under_mouse == scroll_view->scroll_down_button()) {
*part = MenuPart::SCROLL_DOWN; *part = MenuPart::Type::kScrollDown;
return true; return true;
} }
} }
...@@ -1955,7 +1955,7 @@ bool MenuController::GetMenuPartByScreenCoordinateImpl( ...@@ -1955,7 +1955,7 @@ bool MenuController::GetMenuPartByScreenCoordinateImpl(
gfx::Point menu_loc = screen_loc; gfx::Point menu_loc = screen_loc;
View::ConvertPointFromScreen(menu, &menu_loc); View::ConvertPointFromScreen(menu, &menu_loc);
part->menu = GetMenuItemAt(menu, menu_loc.x(), menu_loc.y()); part->menu = GetMenuItemAt(menu, menu_loc.x(), menu_loc.y());
part->type = MenuPart::MENU_ITEM; part->type = MenuPart::Type::kMenuItem;
part->submenu = menu; part->submenu = menu;
part->should_submenu_show = part->should_submenu_show =
part->submenu && part->menu && part->submenu && part->menu &&
...@@ -2151,7 +2151,7 @@ void MenuController::OpenMenuImpl(MenuItemView* item, bool show) { ...@@ -2151,7 +2151,7 @@ void MenuController::OpenMenuImpl(MenuItemView* item, bool show) {
View::ConvertPointFromScreen(item->submenu_->GetWidget()->GetRootView(), View::ConvertPointFromScreen(item->submenu_->GetWidget()->GetRootView(),
&mouse_pos); &mouse_pos);
MenuPart part_under_mouse = GetMenuPart(item->submenu_, mouse_pos); MenuPart part_under_mouse = GetMenuPart(item->submenu_, mouse_pos);
if (part_under_mouse.type != MenuPart::NONE) if (part_under_mouse.type != MenuPart::Type::kNone)
menu_open_mouse_loc_ = mouse_pos; menu_open_mouse_loc_ = mouse_pos;
} }
...@@ -2889,7 +2889,7 @@ void MenuController::RepostEventAndCancel(SubmenuView* source, ...@@ -2889,7 +2889,7 @@ void MenuController::RepostEventAndCancel(SubmenuView* source,
// of the menus from the last run. // of the menus from the last run.
MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu( MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu(
menu_stack_.back().first.item, screen_loc); menu_stack_.back().first.item, screen_loc);
if (last_part.type != MenuPart::NONE) if (last_part.type != MenuPart::Type::kNone)
exit_type = ExitType::kOutermost; exit_type = ExitType::kOutermost;
} }
#if defined(OS_MAC) #if defined(OS_MAC)
...@@ -3136,10 +3136,11 @@ void MenuController::HandleMouseLocation(SubmenuView* source, ...@@ -3136,10 +3136,11 @@ void MenuController::HandleMouseLocation(SubmenuView* source,
if (for_drop_) if (for_drop_)
return; return;
if (part.type == MenuPart::NONE && ShowSiblingMenu(source, mouse_location)) if (part.type == MenuPart::Type::kNone &&
ShowSiblingMenu(source, mouse_location))
return; return;
if (part.type == MenuPart::MENU_ITEM && part.menu) { if (part.type == MenuPart::Type::kMenuItem && part.menu) {
SetSelection(part.menu, part.should_submenu_show ? SELECTION_OPEN_SUBMENU SetSelection(part.menu, part.should_submenu_show ? SELECTION_OPEN_SUBMENU
: SELECTION_DEFAULT); : SELECTION_DEFAULT);
} else if (!part.is_scroll() && pending_state_.item && } else if (!part.is_scroll() && pending_state_.item &&
......
...@@ -320,24 +320,26 @@ class VIEWS_EXPORT MenuController ...@@ -320,24 +320,26 @@ class VIEWS_EXPORT MenuController
// Used by GetMenuPart to indicate the menu part at a particular location. // Used by GetMenuPart to indicate the menu part at a particular location.
struct MenuPart { struct MenuPart {
// Type of part. // Type of part.
enum Type { NONE, MENU_ITEM, SCROLL_UP, SCROLL_DOWN }; enum class Type { kNone, kMenuItem, kScrollUp, kScrollDown };
// Convenience for testing type == SCROLL_DOWN or type == SCROLL_UP. // Convenience for testing type == kScrollDown or type == kScrollUp.
bool is_scroll() const { return type == SCROLL_DOWN || type == SCROLL_UP; } bool is_scroll() const {
return type == Type::kScrollDown || type == Type::kScrollUp;
}
// Type of part. // Type of part.
Type type = NONE; Type type = Type::kNone;
// If type is MENU_ITEM, this is the menu item the mouse is over, otherwise // If type is kMenuItem, this is the menu item the mouse is over, otherwise
// this is NULL. // this is null.
// NOTE: if type is MENU_ITEM and the mouse is not over a valid menu item // NOTE: if type is kMenuItem and the mouse is not over a valid menu item
// but is over a menu (for example, the mouse is over a separator or // but is over a menu (for example, the mouse is over a separator or
// empty menu), this is NULL and parent is the menu the mouse was // empty menu), this is null and parent is the menu the mouse was
// clicked on. // clicked on.
MenuItemView* menu = nullptr; MenuItemView* menu = nullptr;
// If type is MENU_ITEM but the mouse is not over a menu item this is the // If type is kMenuItem but the mouse is not over a menu item this is the
// parent of the menu item the user clicked on. Otherwise this is NULL. // parent of the menu item the user clicked on. Otherwise this is null.
MenuItemView* parent = nullptr; MenuItemView* parent = nullptr;
// This is the submenu the mouse is over. // This is the submenu the mouse is over.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment