summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/button/button_dropdown.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/views/controls/button/button_dropdown.cc')
-rw-r--r--ui/views/controls/button/button_dropdown.cc58
1 files changed, 41 insertions, 17 deletions
diff --git a/ui/views/controls/button/button_dropdown.cc b/ui/views/controls/button/button_dropdown.cc
index 3a0e866..5ee98b3 100644
--- a/ui/views/controls/button/button_dropdown.cc
+++ b/ui/views/controls/button/button_dropdown.cc
@@ -35,6 +35,7 @@ const int kMenuTimerDelay = 500;
ButtonDropDown::ButtonDropDown(ButtonListener* listener, ui::MenuModel* model)
: ImageButton(listener),
model_(model),
+ menu_showing_(false),
y_position_on_lbuttondown_(0),
ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_factory_(this)) {
}
@@ -42,6 +43,14 @@ ButtonDropDown::ButtonDropDown(ButtonListener* listener, ui::MenuModel* model)
ButtonDropDown::~ButtonDropDown() {
}
+void ButtonDropDown::ClearPendingMenu() {
+ show_menu_factory_.InvalidateWeakPtrs();
+}
+
+bool ButtonDropDown::IsMenuShowing() const {
+ return menu_showing_;
+}
+
////////////////////////////////////////////////////////////////////////////////
//
// ButtonDropDown - Events
@@ -49,7 +58,8 @@ ButtonDropDown::~ButtonDropDown() {
////////////////////////////////////////////////////////////////////////////////
bool ButtonDropDown::OnMousePressed(const MouseEvent& event) {
- if (enabled() && IsTriggerableEvent(event) && HitTest(event.location())) {
+ if (enabled() && ShouldShowMenu() &&
+ IsTriggerableEvent(event) && HitTest(event.location())) {
// Store the y pos of the mouse coordinates so we can use them later to
// determine if the user dragged the mouse down (which should pop up the
// drag down menu immediately, instead of waiting for the timer)
@@ -59,8 +69,7 @@ bool ButtonDropDown::OnMousePressed(const MouseEvent& event) {
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&ButtonDropDown::ShowDropDownMenu,
- show_menu_factory_.GetWeakPtr(),
- GetWidget()->GetNativeView()),
+ show_menu_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kMenuTimerDelay));
}
return ImageButton::OnMousePressed(event);
@@ -75,7 +84,7 @@ bool ButtonDropDown::OnMouseDragged(const MouseEvent& event) {
// it immediately.
if (event.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) {
show_menu_factory_.InvalidateWeakPtrs();
- ShowDropDownMenu(GetWidget()->GetNativeView());
+ ShowDropDownMenu();
}
}
@@ -93,7 +102,7 @@ void ButtonDropDown::OnMouseReleased(const MouseEvent& event) {
if (enabled() && event.IsRightMouseButton() && HitTest(event.location())) {
show_menu_factory_.InvalidateWeakPtrs();
- ShowDropDownMenu(GetWidget()->GetNativeView());
+ ShowDropDownMenu();
}
}
@@ -112,7 +121,7 @@ void ButtonDropDown::OnMouseExited(const MouseEvent& event) {
void ButtonDropDown::ShowContextMenu(const gfx::Point& p,
bool is_mouse_gesture) {
show_menu_factory_.InvalidateWeakPtrs();
- ShowDropDownMenu(GetWidget()->GetNativeView());
+ ShowDropDownMenu();
SetState(BS_HOT);
}
@@ -132,7 +141,14 @@ bool ButtonDropDown::ShouldEnterPushedState(const Event& event) {
ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0);
}
-void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) {
+bool ButtonDropDown::ShouldShowMenu() {
+ return true;
+}
+
+void ButtonDropDown::ShowDropDownMenu() {
+ if (!ShouldShowMenu())
+ return;
+
gfx::Rect lb = GetLocalBounds();
// Both the menu position and the menu anchor type change if the UI layout
@@ -156,27 +172,35 @@ void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) {
// Make the button look depressed while the menu is open.
SetState(BS_PUSHED);
+ menu_showing_ = true;
+
// Create and run menu. Display an empty menu if model is NULL.
if (model_) {
MenuModelAdapter menu_delegate(model_);
menu_delegate.set_triggerable_event_flags(triggerable_event_flags());
- MenuRunner runner(menu_delegate.CreateMenu());
- if (runner.RunMenuAt(GetWidget(), NULL,
- gfx::Rect(menu_position, gfx::Size(0, 0)),
- MenuItemView::TOPLEFT,
- MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED)
+ menu_runner_.reset(new MenuRunner(menu_delegate.CreateMenu()));
+ MenuRunner::RunResult result =
+ menu_runner_->RunMenuAt(GetWidget(), NULL,
+ gfx::Rect(menu_position, gfx::Size(0, 0)),
+ MenuItemView::TOPLEFT,
+ MenuRunner::HAS_MNEMONICS);
+ if (result == MenuRunner::MENU_DELETED)
return;
} else {
MenuDelegate menu_delegate;
MenuItemView* menu = new MenuItemView(&menu_delegate);
- MenuRunner runner(menu);
- if (runner.RunMenuAt(GetWidget(), NULL,
- gfx::Rect(menu_position, gfx::Size(0, 0)),
- views::MenuItemView::TOPLEFT,
- MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED)
+ menu_runner_.reset(new MenuRunner(menu));
+ MenuRunner::RunResult result =
+ menu_runner_->RunMenuAt(GetWidget(), NULL,
+ gfx::Rect(menu_position, gfx::Size(0, 0)),
+ MenuItemView::TOPLEFT,
+ MenuRunner::HAS_MNEMONICS);
+ if (result == MenuRunner::MENU_DELETED)
return;
}
+ menu_showing_ = false;
+
// Need to explicitly clear mouse handler so that events get sent
// properly after the menu finishes running. If we don't do this, then
// the first click to other parts of the UI is eaten.