Commit b1d346cc authored by emx's avatar emx Committed by Commit bot

Allow a LocatedEvent to be passed to MenuButton, so the ink drop animation is...

Allow a LocatedEvent to be passed to MenuButton, so the ink drop animation is centered on the click location.

The new constructor overload is used in https://codereview.chromium.org/2832823002/

BUG=635699

Review-Url: https://codereview.chromium.org/2831353002
Cr-Commit-Position: refs/heads/master@{#466922}
parent 393c304c
......@@ -44,12 +44,13 @@ const int MenuButton::kMenuMarkerPaddingRight = -1;
////////////////////////////////////////////////////////////////////////////////
MenuButton::PressedLock::PressedLock(MenuButton* menu_button)
: PressedLock(menu_button, false) {}
: PressedLock(menu_button, false, nullptr) {}
MenuButton::PressedLock::PressedLock(MenuButton* menu_button,
bool is_sibling_menu_show)
bool is_sibling_menu_show,
const ui::LocatedEvent* event)
: menu_button_(menu_button->weak_factory_.GetWeakPtr()) {
menu_button_->IncrementPressedLocked(is_sibling_menu_show);
menu_button_->IncrementPressedLocked(is_sibling_menu_show, event);
}
MenuButton::PressedLock::~PressedLock() {
......@@ -366,7 +367,8 @@ void MenuButton::NotifyClick(const ui::Event& event) {
Activate(&event);
}
void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) {
void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated,
const ui::LocatedEvent* event) {
++pressed_lock_count_;
if (increment_pressed_lock_called_)
*increment_pressed_lock_called_ = true;
......@@ -375,7 +377,7 @@ void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) {
if (snap_ink_drop_to_activated)
GetInkDrop()->SnapToActivated();
else
AnimateInkDrop(InkDropState::ACTIVATED, nullptr /* event */);
AnimateInkDrop(InkDropState::ACTIVATED, event);
}
SetState(STATE_PRESSED);
}
......
......@@ -32,7 +32,10 @@ class VIEWS_EXPORT MenuButton : public LabelButton {
class VIEWS_EXPORT PressedLock {
public:
explicit PressedLock(MenuButton* menu_button);
PressedLock(MenuButton* menu_button, bool is_sibling_menu_show);
// |event| is the event that caused the button to be pressed. May be null.
PressedLock(MenuButton* menu_button,
bool is_sibling_menu_show,
const ui::LocatedEvent* event);
~PressedLock();
private:
......@@ -108,8 +111,10 @@ class VIEWS_EXPORT MenuButton : public LabelButton {
// Increment/decrement the number of "pressed" locks this button has, and
// set the state accordingly. The ink drop is snapped to the final ACTIVATED
// state if |snap_ink_drop_to_activated| is true, otherwise the ink drop will
// be animated to the ACTIVATED node_data.
void IncrementPressedLocked(bool snap_ink_drop_to_activated);
// be animated to the ACTIVATED node_data. The ink drop is animated at the
// location of |event| if non-null, otherwise at the default location.
void IncrementPressedLocked(bool snap_ink_drop_to_activated,
const ui::LocatedEvent* event);
void DecrementPressedLocked();
// Compute the maximum X coordinate for the current screen. MenuButtons
......
......@@ -340,6 +340,37 @@ TEST_F(MenuButtonTest, ActivateDropDownOnMouseClick) {
EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state());
}
// Tests that the ink drop center point is set from the mouse click point.
TEST_F(MenuButtonTest, InkDropCenterSetFromClick) {
TestMenuButtonListener menu_button_listener;
CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
gfx::Point click_point(6, 8);
generator()->MoveMouseTo(click_point);
generator()->ClickLeftButton();
EXPECT_EQ(button(), menu_button_listener.last_source());
EXPECT_EQ(
click_point,
InkDropHostViewTestApi(button()).GetInkDropCenterBasedOnLastEvent());
}
// Tests that the ink drop center point is set from the PressedLock constructor.
TEST_F(MenuButtonTest, InkDropCenterSetFromClickWithPressedLock) {
TestMenuButtonListener menu_button_listener;
CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
gfx::Point click_point(11, 7);
ui::MouseEvent click_event(ui::EventType::ET_MOUSE_PRESSED, click_point,
click_point, base::TimeTicks(), 0, 0);
MenuButton::PressedLock pressed_lock(button(), false, &click_event);
EXPECT_EQ(Button::STATE_PRESSED, button()->state());
EXPECT_EQ(
click_point,
InkDropHostViewTestApi(button()).GetInkDropCenterBasedOnLastEvent());
}
// Test that the MenuButton stays pressed while there are any PressedLocks.
TEST_F(MenuButtonTest, ButtonStateForMenuButtonsWithPressedLocks) {
// Similarly for aura-mus-client the location of the cursor is not updated by
......
......@@ -1522,8 +1522,7 @@ bool MenuController::ShowSiblingMenu(SubmenuView* source,
// There is a sibling menu, update the button state, hide the current menu
// and show the new one.
pressed_lock_.reset(
new MenuButton::PressedLock(button, true /* is_sibling_menu_show */));
pressed_lock_.reset(new MenuButton::PressedLock(button, true, nullptr));
// Need to reset capture when we show the menu again, otherwise we aren't
// going to get any events.
......
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